Skip to content

Instantly share code, notes, and snippets.

@yasamoka
yasamoka / compare.py
Created April 13, 2023 22:46
Compare outputs of md5sum command on multiple files
from argparse import ArgumentParser
from pathlib import Path
from typing import cast
parser = ArgumentParser(
description="Compares outputs of md5sum command on multiple files"
)
parser.add_argument("-i1", type=Path, required=True, help="First input filepath")
parser.add_argument("-i2", type=Path, required=True, help="Second input filepath")
@yasamoka
yasamoka / fixed_model_names.py
Last active October 22, 2022 02:20
SQLAlchemy 2.0 - using declarative mixins with dataclasses example - extended with relationships taking advantage of PEP 681 (dataclass transforms) for synthesis of __init__ based on fields
# Original example at: https://docs.sqlalchemy.org/en/20/orm/dataclasses.html
from dataclasses import dataclass, field
from typing import List, Optional
from sqlalchemy.engine import create_engine
from sqlalchemy.orm import (
Session,
mapped_column,
registry,
@yasamoka
yasamoka / change-brightness
Last active July 1, 2019 17:02
Change display brightness under Ubuntu using keyboard shortcuts
#!/usr/local/bin/python3
import sys
import re
from subprocess import Popen, PIPE
VCP_FEATURE_CODE = 0x10
VCP_FEATURE_NAME = "Brightness"
MIN_VALUE = 0
REGEX_RESPONSE_PATTERN = "VCP code 0x(?P<vcp_feature_code>[0-9a-f]{2}) \((?P<vcp_feature_name>.+?)\s+\)\: current value =\s+(?P<current_value>\d+)\, max value =\s+(?P<max_value>\d+)"
import time
from queue import Queue
from inputs import devices
QUEUESIZE = 20
TARGET_AXIS = "LX"
AXES = {
"ABS_X": "LX",
"ABS_Y": "LY",
import spidev
# credits to http://raspberry.io/projects/view/reading-from-a-mcp3002-analog-to-digital-converter/
# modified by Ramzi Sabra
class MCP3002:
def __init__(self, device=0):
self.conn = spidev.SpiDev(0, device)
self.conn.max_speed_hz = 1200000 # 1.2 MHz
@yasamoka
yasamoka / cncjs-pendant-python-example.py
Created February 3, 2018 05:06
CNC.js pendant Python example
# inspired by cncjs-pendant-raspi-gpio: https://github.com/cncjs/cncjs-pendant-raspi-gpio
# This CNC.js pendant opens a connection to the CNC.js web server, opens a serial port connection,
# writes a command, then terminates.
import jwt
import logging
from socketIO_client import SocketIO, LoggingNamespace
SERVER_ADDRESS = "localhost"
SERVER_PORT = 8000