Skip to content

Instantly share code, notes, and snippets.

View jakelevi1996's full-sized avatar

Jake Levi jakelevi1996

View GitHub Profile
@jakelevi1996
jakelevi1996 / Automating SSH with Putty (Windows).md
Last active February 10, 2023 12:21
Automating SSH with Putty (Windows)

Automating SSH with Putty (Windows)

Putty is a tool which can be used for various purposes, including communicating with a Linux computer using SSH (Secure SHell) from a Windows computer. Given the username, hostname, and password of a Linux machine which is to be SSHed into, Putty can be automated from the command line as follows (assuming Putty is on the Windows path):

putty -ssh username@hostname -pw password

If the same user on the same Linux machine is to be accessed repeatedly, this command can be automated in Windows by creating a shortcut as follows:

  • Right click on the desktop/explorer
@jakelevi1996
jakelevi1996 / 0. Creating a GIF in matplotlib.md
Last active April 3, 2020 17:46
Creating a GIF in matplotlib

Creating a GIF in matplotlib

This Gist provides two examples of how to create a GIF from matplotlib plots using matplotlib.animation.FuncAnimation.

The first movie is created using pre-computed data: a sin-wave which is travelling accross the screen. The second movie is created using data which is calculated bespokely/on-the-fly for each frame, as a function of the frame number; the resulting movie takes about 20% longer to write. The movie in this case is a simple simulation of a standing wave.

In both cases, the results are saved as a GIF; the GIF files are much larger than equivalent MP4 files, however Gisthub will not render an MP4 as part of a Gist, whereas it will render a GIF.

Note that to use animation.PillowWriter, the pillow module must be installed, which can be done using python -m pip install Pillow.

@jakelevi1996
jakelevi1996 / 0. Filter design using scipy.signal.md
Last active February 16, 2020 13:22
Filter design using scipy.signal

Filter design using scipy.signal

This Python script demonstrates some simple examples of windowed FIR filter design using scipy.signal, including

  1. Design of different band-forms (low-pass, high-pass and band-pass)
  2. Using a designed filter to perform filtering on synthetic data
  3. Design of a band-pass filter-bank
  4. Comparison of different filter orders
  5. Comparison of different window functions
@jakelevi1996
jakelevi1996 / Useful Tensorflow 2.1.0 snippets.md
Last active June 17, 2020 00:31
Useful Tensorflow 2.1.0 snippets

Useful Tensorflow 2.1.0 snippets

This is a collection of random things which are useful in Tensorflow 2.1.0, but not necessarily 100% intuitive from the documentation.

View available devices (including GPUs)

To view available devices, use the tf.config.list_physical_devices() command, as described here. The command accepts an optional device_type argument, which for example can be used to only list GPU devices, and returns a list of available devices, EG:

>>> tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
@jakelevi1996
jakelevi1996 / 0. Corona virus simulation.md
Last active March 10, 2020 00:03
Corona virus simulation

Corona virus simulation

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.patches import Patch

# Set simulation details
healthy, sick, recovered, dead = 0, 1, 2, 3
@jakelevi1996
jakelevi1996 / Compiling with CMake.md
Last active March 13, 2020 16:23
Compiling with CMake

Compiling with CMake

As described on the CMake website, "CMake is an open-source, cross-platform family of tools designed to build, test and package software".

To compile a source directory containing a valid CMakeLists.txt file, create and navigate into a dedicated build directory (which may be named build, for example). Run the following command to generate a build system for the current project:

cmake path/to/src
@jakelevi1996
jakelevi1996 / Convert MNIST to NumPy format using TensorFlow and Python.md
Last active March 19, 2020 14:56
Convert MNIST to NumPy format using TensorFlow and Python

Convert MNIST to NumPy format using TensorFlow and Python

The MNIST dataset can be loaded and saved in .npz format as follows (tested in Python 3.7.6, TensorFlow 2.1.0, numpy 1.18.1):

import tensorflow as tf, numpy as np

(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
@jakelevi1996
jakelevi1996 / Special object methods in Python.md
Last active April 17, 2020 11:28
Special object methods in Python

Special object methods in Python

Special methods for Python objects are methods which typically start and end with a double underscore (such as __init__) and have additional uses beyond those of regular methods. They are well documented in the documentation for the Python data model. In this Gist are some particular examples.

Making an object iterable (and unpackable)

The __iter__ method can be used to make an object iterable, which means that, for example, it can be used to the right of in in a for statement. An iterable object can also be used on the right-hand side of tuple-unpacking statements. An object's __iter__ method can just call the built-in iter function on a tuple of its appropriate attributes.

class C:
@jakelevi1996
jakelevi1996 / Useful Powershell commands.md
Last active February 12, 2021 17:39
Useful Powershell commands

Useful Powershell commands

This is a record of things I have found useful in Powershell. It is expected to grow over time.

Viewing information about physical network connections

The Powershell command Get-NetConnectionProfile "gets a connection profile associated with one or more physical network adapters. A connection profile represents a network connection".

With no arguments provided, for each physical network adapter, this provides various pieces of information, such as Name, InterfaceAlias, InterfaceIndex, NetworkCategory, etc.

@jakelevi1996
jakelevi1996 / Calling a C function from Python.md
Last active April 8, 2023 17:00
Calling a C function from Python

Calling a C function from Python

The ctypes module in Python can be used to call a function which has been written and compiled using C. This Gist demonstrates a simple example of a C-function which takes an argument of type in_struct and returns a value of type out_struct (both of these types are defined in the source code), which is compiled into a DLL and called from a Python script.

There are a few quirks to bear in mind when using ctypes:

  • From the section "Return types" of the ctypes documentation: "By default functions are assumed to return the C int type. Other return types can be specified by setting the restype attribute of the function object"
  • If using 64-bit Python, then only 64-bit DLLs can be loaded using ctypes (and similarly for 32-bit Python and 32-bit DLLs); one way to compile 64-bit DLLs in Windows is to use the x86_64-w64-mingw32-gcc C compiler, which can b