Skip to content

Instantly share code, notes, and snippets.

View petri's full-sized avatar

Petri Savolainen petri

View GitHub Profile
@petri
petri / rule_prompt.txt
Last active October 17, 2025 10:28
AI rules generation prompt
Your goal is to produce a file called .rules which explains the outline of the project, so that you (the AI agent) can navigate and modify the project swiftly.
In the file, include information such as:
- Which language(s) the project is written in
- Which tools (such as package manager) and libraries/frameworks (only include major or relevant ones) does the project use, include key components (auth, logging, styling, etc)
- The structure of the project (if it's split into multiple sub-modules, enumerate what each does, and include information on them)
- How the project is deployed (include some information on infrastructure and CI/CD)
- Basic project style guides and guidelines, if applicable
@petri
petri / digicheck.py
Last active January 15, 2025 10:35
Single-file Python digital signature maker and checker
"""digicheck - create and verify signatures for files
Usage:
digicheck keys
digicheck public <keyfilename>
digicheck sign <filename> <keyfilename>
digicheck check <filename> <keyfilename> <signaturefilename>
digicheck (-h | --help)
digicheck --version
@petri
petri / temp.py
Created August 13, 2024 18:49
get raspberry PI temperature straight from /dev/vcio
import os
import struct
import fcntl
from decimal import Decimal
DEVICE_FILE_NAME = "/dev/vcio"
IOCTL_MBOX_PROPERTY = 0xC0046400 # _IOWR(MAJOR_NUM, 0, char *) adjusted for alignment
GET_GENCMD_RESULT = 0x00030080
MAX_STRING = 1024
@petri
petri / Checksum.py
Last active January 24, 2023 21:50 — forked from Zireael-N/Checksum.py
Python script that calculates SHA1, SHA256, MD5 checksums of a given file. Similar to what you might accomplish with eg. ”openssl dgst -sha512 -binary my-downloaded-file.zip | base64”
#!/usr/bin/python
import hashlib
import os
import sys
if len(sys.argv) < 2:
sys.exit('Usage: %s filename' % sys.argv[0])
if not os.path.exists(sys.argv[1]):
@petri
petri / get_products.py
Created August 31, 2022 20:12
get product metadata from web page in Python
import extruct
import requests
from w3lib.html import get_base_url
from urllib.parse import urlparse
url = "https://www.kalevala.fi/collections/korvakorut/products/paratiisi-tappikorvakorut-hopea"
@petri
petri / gist:7210268
Created October 29, 2013 07:14
Some programs such as ssh ask for password and key passphrase via tty, which is not supported by subprocess.Popen. This example illustrates use of pty.fork() to support communications with a child process via a tty (a pty, actually).
"Run git clone using pki key with passphrase."
import pty, os, sys, select
def waitfor(fd, str):
"poll the child for input"
poll = select.poll()
poll.register(fd, select.POLLIN)
while True:
@petri
petri / test.py
Created November 27, 2020 20:56
test example
def test_cmdline_logging_info(caplog, capsys):
retv = tnefparse.cmdline.tnefparse(('-l', 'INFO', '-rb', 'tests/examples/rtf.tnef'))
assert not retv
stdout, _ = capsys.readouterr()
assert len(stdout) == 593
assert caplog.record_tuples == [
('tnefparse', logging.INFO, 'Skipping checksum for performance'),
]
def tnefparse(argv=None):
@petri
petri / bouncer.py
Last active September 28, 2020 14:28
generic helper awaitable to synchronize awaiters chronologically on a first-come first-served basis
class bouncer(Awaitable):
"serve awaiters on a first-come first-served basis"
queue = []
def __init__(self):
type(self).queue.append(self.caller)
@property
def caller(self):
@petri
petri / predicate.py
Last active September 27, 2020 18:48
a first come, first served queing predicate for asyncio Condition
class my_turn:
"""a first come, first served coordinator predicate for
asyncio.Condition.wait_for(predicate); could also do away
the 'caller' by just hardcoding it to the current task
"""
queue = []
def __init__(self, caller):
type(self).queue.insert(0, caller)
@petri
petri / gist:46bb6b8eac8ea5b8f01c90e7414d7951
Last active September 27, 2020 18:42 — forked from HQJaTu/gist:345f7147065f1e10587169dc36cc1edb
Python asyncio ordering test - single-connection multiplex version with asyncio.Queue
#!/usr/bin/env python3
# vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=python
# Proof-of-Concept for https://stackoverflow.com/q/64017656/1548275
# Do Python asyncio Streams maintain order over multiple writers and readers?
import sys
import argparse