Skip to content

Instantly share code, notes, and snippets.

@wireboy5
wireboy5 / usock.py
Last active December 6, 2023 03:04
A very simple socket server and client that allows sending simple one-way commands from a client to a server, and receiving a response back.
"""
# uSock
A very simple socket server and client that allows sending simple one-way commands from a client to a server, and receiving a response back.
"""
try:
import uasyncio as asyncio
import ustruct as struct
MICROPYTHON = True
except ModuleNotFoundError:
@wireboy5
wireboy5 / v5bt.py
Last active September 13, 2023 17:35
"""
Super basic code to scan for and connect to v5 devices using the python bleak library. Prints out all data read over the user port.
"""
import argparse
import asyncio
from bleak import BleakScanner, BleakClient
SERVICE_UUID = "08590f7e-db05-467e-8757-72f6faeb13d5"
@wireboy5
wireboy5 / Makefile
Created November 3, 2022 01:37
x86_64 multiboot2 long mode bootstrap.
run: build
qemu-system-x86_64 image.iso
build:
nasm -f elf64 bootstrap.asm -o bootstrap.o
ld -z max-page-size=0x1000 -S -o kernel.elf -Tlink.ld bootstrap.o
mv kernel.elf image/boot/kernel.elf
grub-mkrescue -o image.iso image
{
"arch": "arm",
"data-layout": "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64",
"disable-redzone": true,
"emit-debug-gdb-scripts": false,
"env": "newlib",
"executables": true,
"features": "+v7,+thumb2,+soft-float,-neon,+strict-align",
"linker": "arm-none-eabi-gcc",
"linker-flavor": "gcc",
from loguru import logger
def catch_all_continue(func):
"""
This is probably the most useful function I have ever written.
It wraps any async function, and when there is an exception, it logs it and continues on like nothing ever happened.
This works amazing for web servers. Just wrap the server handler function in this and you are good to go.
Only requires loguru, however loguru can be switched for anything else. (Although I like it best)
Self imports functools just in case you do not want clutter in the project.
"""
## Delta Encoding for bytes of the same size in a single line lambda function. No external or standard libraries required
deltaSameLength = lambda d1,d2: b''.join([bytes().fromhex(hex(b1^b2).replace("0x","").rjust(2,"0")) for b1,b2 in zip(d1,d2)])