Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mikalv's full-sized avatar

Mikal mikalv

View GitHub Profile
@mikalv
mikalv / fields.py
Created April 9, 2024 14:05 — forked from evert0n/fields.py
Virtual Field for Django
from django.db.models import Field
from django.conf import settings
from django.utils.decorators import cached_property
class VirtualField(object):
"""
A virtual field, mainly used for caching and seamless computed field retrieval.
This acts both like a (cached) property and a virtual field if supported.
"""
@mikalv
mikalv / tesla-key-card-protocol.md
Created September 20, 2023 22:27 — forked from darconeous/tesla-key-card-protocol.md
Tesla Key Card Protocol

Tesla Key Card Protocol

Researched by Robert Quattlebaum darco@deepdarc.com.

Last updated 2020-02-03.

Image of Tesla Key Card Image of Tesla Model 3 Key Fob

@mikalv
mikalv / esphome_ble_config.yaml
Created February 17, 2023 09:00 — forked from kmdm/esphome_ble_config.yaml
esphome, esp32 ble tracker and Home Assistant mqtt_room sensors
# MQTT broker configuration
mqtt:
broker: !secret mqtt_broker
username: !secret mqtt_username
password: !secret mqtt_password
discovery: False # Only if you use the HA API usually
id: mqtt_client
# Define the room for this ESP32 node
substitutions:
@mikalv
mikalv / update_notifications.yaml
Created January 28, 2023 01:35 — forked from mdegat01/update_notifications.yaml
Update Notifications Automation Blueprint
blueprint:
name: Update notifications
description: Send notifications for new updates and install or skip on action
homeassistant:
min_version: '2022.4.0'
domain: automation
input:
update_entities:
name: Update entities
description: >-
@mikalv
mikalv / README-oneshot-systemd-service.md
Created December 5, 2022 22:21 — forked from drmalex07/README-oneshot-systemd-service.md
An example with an oneshot service on systemd. #systemd #systemd.service #oneshot

README

Services declared as oneshot are expected to take some action and exit immediatelly (thus, they are not really services, no running processes remain). A common pattern for these type of service is to be defined by a setup and a teardown action.

Let's create a example foo service that when started creates a file, and when stopped it deletes it.

Define setup/teardown actions

Create executable file /opt/foo/setup-foo.sh:

@mikalv
mikalv / camera.py
Created September 21, 2022 13:30 — forked from alfonsrv/camera.py
Motion detection with OpenCV + grab static snapshot every 1 second from RTSP video stream
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Copyright (c) Rau Systemberatung GmbH (rausys.de)
# MIT License
# credits: https://pyimagesearch.com/start-here/
import argparse
import os
from datetime import datetime, timedelta
@mikalv
mikalv / application.ex
Created August 30, 2022 17:42 — forked from cblavier/application.ex
Cowboy 2.5 proxy, used to bind a single port (on Heroku) for umbrella Phoenix applications. It supports HTTPS and websockets properly.
defmodule MasterProxy.Application do
alias MyApp.Endpoint, as: MyAppEndpoint
alias MyApp.UserSocket, as: MyAppUserSocket
alias MyOtherApp.Endpoint, as: MyOtherAppEndpoint
alias MyOtherApp.UserSocket, as: MyOtherAppUserSocket
alias Phoenix.LiveReloader.Socket, as: LiveReloadSocket
alias Plug.Cowboy
@mikalv
mikalv / datetime_parser.ex
Created August 20, 2022 02:06 — forked from bluzky/datetime_parser.ex
Elixir datetime parser with regex
defmodule DateTimeParser do
@mapping %{
"H" => "(?<hour>\\d{2})",
"I" => "(?<hour12>\\d{2})",
"M" => "(?<minute>\\d{2})",
"S" => "(?<second>\\d{2})",
"d" => "(?<day>\\d{2})",
"m" => "(?<month>\\d{2})",
"y" => "(?<year2>\\d{2})",
"Y" => "(?<year>-?\\d{4})",
nginx conf for proxying the FreeIPA UI. ipa.my.org is the proxy name, realipa.my.org is the master.
server {
listen 443 ssl;
server_name ipa.my.org;
ssl on;
ssl_certificate /etc/nginx/ssl/ipa.crt;
ssl_certificate_key /etc/nginx/ssl/ipa.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers AES256+EECDH:AES256+EDH:AES128+EECDH!aNULL;
@mikalv
mikalv / go-switch-bash
Created July 1, 2022 11:11 — forked from AnomalRoil/go-switch-bash
The `go switch` function allows you to easily switch you current Go version
# to add to your ~/.bashrc or your ~/.zshrc file. Usage: $ go switch 1.18.1
function go() {
case $* in
switch* )
shift 1
gobindir=$(go env GOBIN)
# adapt to a valid directory at the beginning of your $PATH if you're not on systemd
homebindir=$(systemd-path user-binaries)
go install golang.org/dl/go"$@"@latest
$gobindir/go"$@" download