Skip to content

Instantly share code, notes, and snippets.

@Bouni
Bouni / async-db-update.py
Created September 3, 2021 15:09
Read JLCPCB library CSV and write async it to a Postgres DB
import asyncio
import csv
import time
from typing import Optional
from slugify import slugify
from sqlalchemy.ext.asyncio import create_async_engine
from sqlmodel import Field, Session, SQLModel, create_engine, select
from sqlmodel.ext.asyncio.session import AsyncSession
@Bouni
Bouni / lcsc.py
Last active June 9, 2023 15:12
LCSC API python example
from pprint import PrettyPrinter
import requests
pp = PrettyPrinter()
def query(number)
url = f"https://wwwapi.lcsc.com/v1/products/detail?product_code={number}"
r = requests.get(url)
pp.pprint(r.json())
@Bouni
Bouni / idealo-compare.py
Last active July 30, 2021 11:29
Idealo Artikeldatenblatt Vergleich
import requests
import xlsxwriter
from bs4 import BeautifulSoup
urls = [
"https://www.idealo.de/preisvergleich/OffersOfProduct/201429002_-cpt251ni-chiq.html",
"https://www.idealo.de/preisvergleich/OffersOfProduct/200804867_-ltb1af28w0-electrolux.html",
"https://www.idealo.de/preisvergleich/OffersOfProduct/200997990_-skg312nf-ix-wolkenstein.html",
]
@Bouni
Bouni / fancontroller.yaml
Created July 22, 2021 09:25
ESP Home fan controller
substitutions:
devicename: "fancontroller-1"
upper_devicename: "Fan controller 1"
# GPIO config
fan_1_power_pin: GPIO16
fan_1_pwm_pin: GPIO17
fan_2_power_pin: GPIO21
fan_2_pwm_pin: GPIO22
status_led_pin: GPIO2
@Bouni
Bouni / sp111.yml
Last active February 1, 2023 12:34
ESPHome config for Gosund SP111 V1.4 powerplugs
---
substitutions:
devicename: "powerplug-1"
upper_devicename: "Powerplug 1"
# Higher value gives lower watt readout
current_res: "0.002452"
# Lower value gives lower voltage readout
voltage_div: "939"
# GPIO config
sel_pin: GPIO12
@Bouni
Bouni / LinuxCNC-Ethercat.md
Last active April 30, 2025 06:10
Linux CNC + EtherCat + RPi 4 Setup

The folowing is a writup from Hakans forum post!

RPi Setup

  1. Download & Write image to SD card: www.linuxcnc.org/iso/linuxcnc-2.8.1-pi4.zip
  2. Configure Wifi via wpa_supplicant.conf
  3. Put SD card into RPi and verify that RT-PREEMT Kernel is running: uname -a
  4. Update everything and reboot: sudo apt update && sudo apt upgrade && sudo reboot
@Bouni
Bouni / hcp.cpp
Created May 27, 2021 13:12
Hoermann HCP protocoll test on ESP32 (syncbreak hack)
/* vim:set sw=2: */
#include <Arduino.h>
#define RX2 21
#define TX2 22
#define DIR 17
int rx = 0;
@Bouni
Bouni / flexicompact.py
Last active February 23, 2021 06:43
Communicate with a SICK FlexiCompact ove Modbus TCP
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadBuilder, BinaryPayloadDecoder
class FlexiCompact:
def __init__(self, ip, port=502, unit=1):
@Bouni
Bouni / Default%20Settings
Last active February 10, 2021 07:08
KiTTY Default Settings - Solarized dark
Present\1\
HostName\\
LogFileName\kitty.log\
LogType\0\
LogFileClash\-1\
LogFlush\1\
LogHeader\1\
SSHLogOmitPasswords\1\
SSHLogOmitData\0\
Protocol\ssh\
#!/usr/bin/bash
# Script in /opt ablegen
server="192.168.100.100"
port=22
while true; do
if ! nc -z $server $port 2>/dev/null; then
kill -9 xinit-login