Skip to content

Instantly share code, notes, and snippets.

View Tobi-De's full-sized avatar
👁️‍🗨️
Trade-offs everywhere!

Tobi Tobi-De

👁️‍🗨️
Trade-offs everywhere!
View GitHub Profile
@adamghill
adamghill / justfile
Created July 6, 2024 20:20
Example justfile for Python projects
# https://just.systems
set quiet
set dotenv-load
set export
# List commands
_default:
just --list --unsorted --justfile {{justfile()}} --list-heading $'Available commands:\n'
@danjac
danjac / form.html
Last active March 12, 2024 15:52
Django form using AlpineJS to render rating field
{#
class ReviewForm(forms.ModelForm):
class Meta:
model = Review
fields = (
"comment",
"score",
)
help_texts: ClassVar = {
@willmcgugan
willmcgugan / last_lines.py
Created March 2, 2024 16:10
Get the last lines from a file
import mmap
def get_last_lines(path: str, count: int) -> list[str]:
"""Get count last lines from a file."""
with open(path, "r+b") as text_file:
text_mmap = mmap.mmap(text_file.fileno(), 0, mmap.ACCESS_READ)
position = len(text_mmap)
while count and (position := text_mmap.rfind(b"\n", 0, position)) != -1:
count -= 1
@adamghill
adamghill / deploy-to-caprover.yml
Last active November 26, 2023 19:36
GitHub Action to build and deploy Docker image to CapRover
# Might be outdated! Check https://github.com/marketplace/actions/build-docker-and-deploy-to-caprover for the latest version.
name: Create and publish Docker image to CapRover
# Requires the following Action secrets to be set in your GitHub repo:
# - CAPROVER_APP_TOKEN
# - CAPROVER_SERVER_URL
on:
push:
@tonybaloney
tonybaloney / tidy.sh
Last active April 22, 2023 20:17
tidy script
# Delete all forks that haven't been updated since 2020
gh auth refresh -h github.com -s delete_repo
gh search repos \
--owner tonybaloney \
--updated="<2020-01-01" \
--include-forks=only \
--limit 100 \
--json url \
--jq ".[] .url" \ | xargs -I {} gh repo delete {} --confirm
@ewagner12
ewagner12 / Fedora35Hibernation.md
Last active September 1, 2025 03:03 — forked from eloylp/Fedora35Hibernation.md
Fedora 37 Silverblue/Kinoite hibernation with swapfile, only for hibernation and resume

Fedora37 Silverblue/Kinoite hibernation

This guide helps to configure the hibernation on an ostree (Silverble/Kinoite) Fedora37 (also worked fine in previous Fedora34) installation by using a swap file. The Fedora37 installation comes with btrfs as default filesystem. Also, it comes with a zram swap device:

$ swapon
NAME       TYPE      SIZE USED PRIO
/dev/zram0 partition   8G   0B  100
@nymous
nymous / README.md
Last active September 13, 2025 07:56
Logging setup for FastAPI, Uvicorn and Structlog (with Datadog integration)

Logging setup for FastAPI

This logging setup configures Structlog to output pretty logs in development, and JSON log lines in production.

Then, you can use Structlog loggers or standard logging loggers, and they both will be processed by the Structlog pipeline (see the hello() endpoint for reference). That way any log generated by your dependencies will also be processed and enriched, even if they know nothing about Structlog!

Requests are assigned a correlation ID with the asgi-correlation-id middleware (either captured from incoming request or generated on the fly). All logs are linked to the correlation ID, and to the Datadog trace/span if instrumented. This data "global to the request" is stored in context vars, and automatically added to all logs produced during the request thanks to Structlog. You can add to these "global local variables" at any point in an endpoint with `structlog.contextvars.bind_contextvars(custom

@phoe
phoe / forever.md
Last active June 21, 2025 13:28
Forever Stable Branch

Forever Stable Branch

Stable branch, I can see you in the stable branch
See you again, I see you again
In my dreams, in my dreams, in my dreams, in my dreams

Morning light, I remember the morning li-i-i-i-ight
Outside my door (outside my door), I'll see you no more (see you no more)
In my dreams, in my dreams, in my dreams, in my dreams
>

@Tobi-De
Tobi-De / utils.py
Last active July 6, 2023 11:07
Some django utils I usually have in my projects
# render pdf using weasyprint
# depends on: weasyprint
import weasyprint
from django.template.loader import render_to_string
def render_to_pdf(template_src, context_dict=None):
html = render_to_string(template_src, context_dict)
try:
pdf = weasyprint.HTML(string=html).write_pdf()
except Exception as e: