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 / numpyPipe.md
Last active March 16, 2018 16:59
Piping numpy arrays to other processes

To pipe data from one process to another as a stream in python we need to pickle the object and pass it to the pipe stream. In this example I've used Numpy arrays but this could be applied to any object that can be pickled in Python. This took far too long to get working and I could find little information online on how to put it all together so here it is. This code is Python 3 only, I've only run this on a Mac.

I've used binary as the stream rather than text purley becuase of effiencies. Numpy arrays can get huge! This means readline() is not going to work. Instead, I send a single control byte , 1, for data and 0 for stop. This could be extended to include other control operations. I then send the length of the data as a 8 byte int, followed by the data itself.

simpleSend.py

@docPhil99
docPhil99 / pandoc_lectures.md
Last active February 12, 2019 10:56
Making lecture notes with pandoc
  1. Install a markdown editor. I have used Atom with the following packaged added
    • markdown-preview-plus to view your pdf as you edit. This isn't configured to render the beamer slides but it produced a normal pdf document as you type which is still handy.
    • highlight-bad-chars - highlights none acsii chars that cause latex a problem
    • pdf-view is also handy - it opens your created pdf files directly in Atom.
    • Language Markdown - for some md auto formatting
    • Optional tweeks for Atom: In the core package Autocomplete-plus I would suggest changing 'Keymap For Confirming A Suggestion' to 'tab always, enter when suggestion explicity selected'. The default tab and enter is fine for programming but doesn't work well when writting English.
  2. Install latex - there are lots of ways of doing this depending on your OS. Make sure you have beamer installed as well.
  3. Install pandoc. The repo versions might be really old, so I installed the latest from here.
  4. Install any templates
@docPhil99
docPhil99 / git_cheat_sheet.md
Last active March 2, 2020 16:27
Some useful notes on git

Split directory into a new repo

  • clone the repo into a new directory
  • cd into it
  • git filter-branch --prune-empty --subdirectory-filter FOLDER-NAME BRANCH-NAME
    • where:
    • FOLDER-NAME: The folder within your project that you'd like to create a separate repository from.
    • BRANCH-NAME: The default branch for your current project, for example, master.
  • Update the remote git remote set-url origin https://github.com/USERNAME/NEW-REPOSITORY-NAME.git
  • Verify git remote -v
  • Push the changes git push -u origin BRANCH-NAME
@docPhil99
docPhil99 / ffmpeg.md
Last active July 24, 2020 10:12
Some useful command in ffmpeg

Speed

  • ffmpeg -i input.mkv -filter:v "setpts=0.5*PTS" output.mkv increases doubles playback speed, by dropping frames see

Playback

  • ffmpeg -i input.mp4 -f opengl "window title" or use ffplay

Convertion

  • ffmpeg -i video.flv video.mpeg
@docPhil99
docPhil99 / ffmpeg_stream.md
Last active August 25, 2020 09:11
Streaming FFmpeg and Python

This is running on Linux Mint

  1. Install ffmpeg
sudo apt-get install ffmpeg
  1. A simple test: open two terminals, in first run ffplay udp://127.0.0.1:23000 and in the second ffmpeg -i sample.mp4 -vcodec mpeg4 -f mpegts udp://127.0.0.1:23000 . This should play the video sample.mp4 although the quality is rather blocky.

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 / testing_tensorflow_keras.md
Created December 7, 2020 15:26
Code for testing a custom layer in tensorflow 2 Keras

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)
@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.

@docPhil99
docPhil99 / igtv_bars.md
Last active March 29, 2021 12:51
Add bars to video for IGTV

To convert a video to 16x9 or 9x16 by adding black bars use ffmpeg as follows ffmpeg -i film1.mp4 -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1" film1_bars.mp4

This add bars to the top and bottom, flip both of the 1920:1080 to 1080:1920 for horizontal bars (better for computer monitors, TV etc)

Note IGTV also requires h.264 and a max of 30fps.

Thanks to https://stackoverflow.com/a/46693766/3361398