Skip to content

Instantly share code, notes, and snippets.

Avatar

Phil docPhil99

  • University of Sussex
View GitHub Profile
@docPhil99
docPhil99 / video_play_back.md
Last active Mar 31, 2022
playback of F-log video with LUT on linux
View video_play_back.md

Apply a cube LUT to mpv playback mpv -vf=lut3d=XT4_FLog_FGamut_to_ETERNA_BT.709_33grid_V.1.01.cube FILE.MOV or celluloid --mpv--vf=lut3d=XT4_FLog_FGamut_to_ETERNA_BT.709_33grid_V.1.01.cube FILE.MOV

@docPhil99
docPhil99 / loguru.md
Created Dec 10, 2021
Python Loguru Hacking
View loguru.md

Loguru is my favorite why to perform logging in python. It's generally so simple to use but a few things are missing from the documentation.

Logging over the network

This is based on the loguru example, but also includes the hostname of the sender. To add extra fields the pefered method is to add to record["extra"] dictionary (which is normally empty). The client code sends the log messages over the network and to stderr.

class LoggingSocketHandler:
 def __init__(self, host, port, timeout=600):
@docPhil99
docPhil99 / stop_bash_on_error.md
Created Oct 20, 2021
Stop bash background commands on error
View stop_bash_on_error.md

I have simple bash script that starts lots of processes. If one fails I want to stop everything. There maybe a better way to do this but I came up with this.

First create two scripts to test our main script. good_sleep that sleeps for 10 seconds and exits with no error.

#!/bin/bash
echo " good sleeping"
sleep 10
echo "done"
@docPhil99
docPhil99 / mint_dual_monitor.md
Last active Nov 17, 2021
Dual Monitor fixes in Linux Mint
View mint_dual_monitor.md

Dual Monitor Linux Mint Login SCreen Fix

Linux mint has a few annoyances when using dual monitors. First fixing the log in screen. By default it uses the same resolution as the primary monitor in the secondary screen. It's only cosmentic but it annoys me.

Create or append the file /etc/lightdm/lightdm.conf.d/71-linuxmint.conf to add

[SeatDefaults]
user-session=cinnamon
display-setup-script=/usr/bin/lightdmxrandr.sh
@docPhil99
docPhil99 / heic_to_jp_fish.md
Last active Jul 31, 2021
Batch convert heic files to jpg in fish shell
View heic_to_jp_fish.md

Batch convert heic files to jpg in fish shell

  • First install sudo apt install libheif-examples
  • Then run in correct directory for p in *.heic; heif-convert $p (basename $p .heic)".jpg"; end
@docPhil99
docPhil99 / Mulled_wine.md
Last active Dec 23, 2020
My mulled wine!
View Mulled_wine.md
  1. Make the spice mix:
  • 1 Tbs ground allspice
  • 1 Tbs ground cinnamon
  • 1 Tbs ground nutmeg
  • 1 tsp ground cloves
  • 1 tsp ground coriander
  • 1 tsp ground ginger

You can keep the leftovers in a jar.

@docPhil99
docPhil99 / video_loop_back.md
Last active Jan 8, 2021
How to pass video to a dummy webcam.
View video_loop_back.md
  1. Start the v4l2loopback module:
sudo modprobe v4l2loopback \
      devices=1 exclusive_caps=1 video_nr=5 card_label="Dummy Camera"
  1. I have a short test video call Speed1.avi, this can be played streamed to /dev/video5 with ffmpeg -re -stream_loop -1 -i Speed1.avi -vcodec rawvideo -pix_fmt yuv420p -f v4l2 /dev/video5
@docPhil99
docPhil99 / testing_tensorflow_keras.md
Created Dec 7, 2020
Code for testing a custom layer in tensorflow 2 Keras
View testing_tensorflow_keras.md

A simple example of code for testing a custom tensorflow Keras layer

    def my_init(shape, dtype=None):
        """This function is a custom kernel initialiser. It loads the weights from a matlab file. Adapt as need"""
        matlab = io.loadmat('../matlab/weights.mat')
        wfilter = matlab['wfilter']
        if shape != wfilter.shape:
            raise Exception('Shaped do not match')
 return tf.constant(wfilter, dtype=dtype)
View python_docker.md

This is running on Linux Mint 20

  • Install docker.
    • sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common

    • curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

    • sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(. /etc/os-release; echo "$UBUNTU_CODENAME") stable"

    • sudo apt-get update

    • sudo apt install docker-ce docker-compose

    • sudo usermod -aG docker $USER

  • and test with docker --version
@docPhil99
docPhil99 / controlling_ha.md
Last active Aug 5, 2021
Controlling Home Assistant remotely via curl
View controlling_ha.md

It's actually fairly easy to control Home Assistant remotely using curl but I couldn't find a complete solution on how to do this, so here goes...

  1. Activate the api in configuration.yaml by adding the line api:
  2. Get an Authorization token from HA (It's a Long-Lived Access Tokens which can be created on your HA user profile page)
  3. This list of exposed states can be found using curl -X GET -H "Authorization: Bearer YOUR_TOKEN" -H "Content-Type: application/json" http://YOUR_IP:8123/api/states | prettyjson
  • Note prettyjson is an alias for python -m json.tool, you don't need this it's just easier to read.
  1. To get the state of a device append the entity.id to the URL, eg curl -X GET -H "Authorization: Bearer YOUR_TOKEN" -H "Content-Type: application/json" http://YOUR_IP:8123/api/states/switch.mylight | prettyjson
  2. The API documentation shows you how to change the states but this does not actually turn on the lights, etc. Instead, us