Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View docPhil99's full-sized avatar

Phil docPhil99

  • University of Sussex
View GitHub Profile
@docPhil99
docPhil99 / rename_USB_device.md
Created December 23, 2023 13:17
Renaming USB sound card

My USB speakers seem to have some buggy firmware in that the device name has been corrupted with some binary. At first I thought it was unicode, but uni2ascii said overwise. Since I need to be able to type the name into config files I had to rename the device using udev.

First we need to fine the name of the device. Run udevadm monitor --kernel --subsystem-match=sound

Unplug and re-plug in the DAC, this results in:


KERNEL[1585.716702] remove   /devices/pci0000:00/0000:00:12.0/usb4/4-5/4-5:1.0/sound/card1/controlC1 (sound)
@docPhil99
docPhil99 / Goodman_speckle_test.py
Last active April 17, 2023 11:18
Python version of Joseph Goodman's Mathematica code for simulating laser speckle. Both free space and in an optical system are combined into the one file.
# my conversion of Goodman's code
import numpy as np
import matplotlib.pyplot as plt
# Program for simulating Speckle Formation by Free Space Propagation
# Translate from Mathematica
# Ref: Goodman, Joseph W. 2020. Speckle Phenomena in Optics: Theory and Applications, Second Edition. SPIE.
n = 1024 # nxn array size
@docPhil99
docPhil99 / pi_networking.md
Last active November 10, 2023 00:16
Setup a Raspberry Pi (or any Ethernet enabled device) on a private network

My system consists of a host PC that has two ethernet cards. What I want to do is use one for connecting to the inernet and the other to run a private network of Raspberry Pi computers.

My first ethenet card is easy, it's basically grabbing its setting via DHCP from my router. What I need to do is create a different subnet for the second card. So first of all I need to look up current IP address. On linux I can run ip a I need to find the address and mask from there. In my case it's the line starting inet 192.168.86.36/24 The 24 is mask, in this case the last digit of the IP address are all on the same subnet. See https://www.calculator.net/ip-subnet-calculator.html here if you want to calculate your own range.

For the second card I need to pick a static IP address that's on a different subnet. There are a number of IP address that are reserved for private networks so it's best to use one of these.

Class A- 10.0.0.0 to 10.255.255.255
Class B- 172.16.0.0 to 172.31.255.255
Class C- 192.168.0.0 to 19
@docPhil99
docPhil99 / batch_convert_HEIC.md
Last active September 22, 2022 10:42
Fish shell tips - a work in progress

Batch convert HEIC using a fish shell

for p in *.HEIC;
  heif-convert $p (path change-extension jpg $p)
end

Note the path command required fish 3.5

@docPhil99
docPhil99 / video_play_back.md
Last active March 31, 2022 13:34
playback of F-log video with LUT on linux

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
Last active June 29, 2023 12:33
Python Loguru Hacking

Loguru is my favorite way 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 October 20, 2021 14:03
Stop bash background commands on error

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 January 27, 2023 13:36
Dual Monitor fixes in Linux Mint

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. My secondary monitor is much larger so it doesn't display correctly. It's only cosmentic but it annoys me.

Create or append the file /etc/lightdm/lightdm.conf.d/70-linuxmint.conf so that it has the lines

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

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 December 23, 2020 20:20
My mulled wine!
  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.