Skip to content

Instantly share code, notes, and snippets.

View keriszafir's full-sized avatar

Keri Nikola Szafir keriszafir

View GitHub Profile
@keriszafir
keriszafir / README.md
Created March 27, 2023 09:30 — forked from HeedfulCrayon/README.md
Script for OBS Studio to publish session stats to MQTT broker with autodiscovery set up for Home Assistant

OBS MQTT Status to Home Assistant

Setup:

  1. Download script
  2. Install mqtt-wrapper pip install mqtt-wrapper
  3. Open OBS Studio
  4. In OBS Studio add a script (Tools -> Scripts)
  5. Configure script parameters (my base channel is homeassistant and my sensor name is obs, creating the path homeassistant/sensor/obs)

script_parameters

@keriszafir
keriszafir / config.py
Last active December 15, 2019 15:34
configuration module with attribute-like option access and json file data storage
# -*- coding: utf-8 -*-
"""Configuration class storing data as jsonfile.
Written for micropython which has no configparser module, but can be
used on regular python as well. The goal is to make a configuration class
that is simpler and less painful to use than ConfigParser."""
try:
# micropython module
import ujson as json
except ImportError:
@keriszafir
keriszafir / click-edit-wrapper.py
Created February 13, 2017 15:08
click edit wrapper for nano with autosave
import click
def edit(text=''):
"""Use nano as a preferred editor with autosave on exit
(easier on the user).
If nano is not available (e.g. on Windows),
use any editor found on the system"""
try:
edited_text = click.edit(text, editor='nano -t', require_save=False)
except click.ClickException:
edited_text = click.edit(text, require_save=False)
#!/usr/bin/env python3
"""Database fix for rpi2caster 0.4:
layout was: [(char1, [style1, style2...], column1, row1, units1),
(char2, [style1, style2...], column2, row2, units2),...]
now is: [(char1, styles1, coords1, units1),
(char2, styles2, coords2, units2),...]
(simplified the styles and coordinates)
"""
from rpi2caster import database
DB = database.Database()
@keriszafir
keriszafir / rpi2caster_db_fix_03.py
Last active March 27, 2016 13:04
Database fix for rpi2caster 0.3 - store wedge definitions in a single column
#!/usr/bin/env python3
import os
from rpi2caster import database
from rpi2caster import matrix_data
DB = database.Database()
def correct_diecases():
@keriszafir
keriszafir / python-oop-with-context
Last active August 29, 2015 14:15
OOP with context test and explanation
#!/usr/bin/python
class Foo(object):
def __init__(self):
print('Initializing Foo')
def __enter__(self):
print('Entering Foo context')
return self
def __exit__(self, *args):
print('Exiting Foo context')
def Foomethod(self):
@keriszafir
keriszafir / gpio-interrupt.c
Last active November 8, 2023 10:40
gpio-interrupt - C routine for handling interrupts generated on GPIO
/* Demonstration C GPIO interrupt handling routine for Raspberry Pi
This is a modified code found at https://github.com/phil-lavin/raspberry-pi-gpio-interrupt
The program displays a notice whenever you:
-turn on the Raspberry Pi's pin 11 (apply 3.3V),
-turn the pin off.
This routine uses wiringPi library (follow the installation instructions at wiringpi.com),
and should be compiled with a command: