Skip to content

Instantly share code, notes, and snippets.

View jakelevi1996's full-sized avatar

jakelevi1996

View GitHub Profile
@jakelevi1996
jakelevi1996 / make_poly_table.py
Last active March 7, 2024 14:53
Make Latex table of polynomial coefficients
from jutility import util
def main():
p = util.Printer("poly_table", file_ext="tex", print_to_console=False)
b_deg = 5
a_deg = 7
p("\\documentclass{article}")
p("\\usepackage{subcaption}")
@jakelevi1996
jakelevi1996 / Comparing_normalisation_for_weight_initialisation.png
Last active February 23, 2024 12:17
Comparing normalisation for weight initialisation
Comparing_normalisation_for_weight_initialisation.png
@jakelevi1996
jakelevi1996 / Combined_output.png
Last active January 19, 2024 12:11
Compare capture/recapture statistics for different sample sizes and population sizes
Combined_output.png
@jakelevi1996
jakelevi1996 / make_gym_gif.py
Last active November 1, 2023 15:29
Make GIF of OpenAI gym environment
from jutility import util, plotting
import gymnasium as gym
def main():
table = util.Table(
util.CountColumn("c"),
util.TimeColumn("t"),
print_interval=util.TimeInterval(1),
)
@jakelevi1996
jakelevi1996 / diagram_fm.py
Last active July 31, 2023 22:35
Make tables and trees for recursive functions defined in Chapter 5 of GEB
from jutility import util
import tree
def diagram_fm(n_max, printer):
table = util.Table(
util.Column("n", width=10, title="n"),
util.Column("f_n", width=10, title="F(n)"),
util.Column("m_n", width=10, title="M(n)"),
util.Column("m_f_n", width=10, title="M(F(n))"),
util.Column("f_m_n", width=10, title="F(M(n))"),
@jakelevi1996
jakelevi1996 / minimise_function_z3.py
Last active July 7, 2023 22:45
Symbolically minimise function with z3
# Remember to install z3 with `python -m pip install z3-solver` (instead of
# `python -m pip install z3`) !
import z3
import numpy as np
f = lambda x: (x - 2) * (x - 3) * (x - 4)
x = z3.Real("x")
y = z3.Real("y")
z = z3.Real("z")
@jakelevi1996
jakelevi1996 / .delta_sigma_modulation.md
Last active April 24, 2023 15:07
Delta-sigma modulation demo

Delta-sigma modulation demo

  • Delta-sigma modulation is a technique for ADC (analog to digital conversion), which converts a continuous-time, continuous-voltage input signal into a discrete-time, binary-voltage output signal, from which the original input signal can later be recovered
  • There is a description of delta-sigma modulation on Wikipedia (although it is not the most concise or helpful of Wikipedia articles)
  • Below are explanations of the basic technique of delta-sigma modulation and how to recover the input signal, a simple Python implementation of modulation and recovery (in 10 + 3 lines of code + generating input data and plotting), and some visualisations of a sinusoidal input signal, its delta-sigma modulated output signal, the recovered input signal, and the time integral of each signal respectively

Basic technique

  • The basic principle of delta-sigma modulation is to output either +delta or -delta (where delta is a given pa
@jakelevi1996
jakelevi1996 / solve_digits_puzzle.py
Last active June 19, 2023 13:40
Solve digits puzzle
""" Solve a digits puzzle from https://www.nytimes.com/games/digits
TODO: don't duplicate calculations of equivalent commutative operations
Usage example (make 495 from [5, 6, 10, 11, 18, 12]):
python solve_digits_puzzle.py 495 5 6 10 11 18 12
Example of solving a difficult Countdown numbers problem (
https://youtu.be/pfa3MHLLSWI ):
@jakelevi1996
jakelevi1996 / Fix Gists not pushing.md
Last active June 22, 2024 17:08
Fix Gists not pushing

Fix Gists not pushing

Problem: pushing to Github Gist returns 403 error, as shown below:

$ git push
remote: Permission to write to gist denied.
fatal: unable to access 'https://gist.github.com/USERNAME/GISTNAME/': The requested URL returned error: 403