Skip to content

Instantly share code, notes, and snippets.

-- PyXHDL support functions.
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.math_real.all;
use ieee.float_pkg.all;
package pyxhdl is
type uint_array1d is array(natural range <>) of unsigned;
/* verilator lint_off WIDTH */
`timescale 1 ns / 100 ps
package fp;
let MAX(A, B) = ((A > B) ? A : B);
let MIN(A, B) = ((A > B) ? B : A);
let ABS(A) = (($signed(A) >= 0) ? A : -$signed(A));
let FABS(A) = ((A >= 0.0) ? A : -A);
@davidel
davidel / pip_publish
Created February 18, 2026 16:15
Publish PyPi Package From RO FileSystem
#!/bin/bash
if [ $# -lt 1 ]; then
echo "Use: $0 SRC_FOLDER"
exit 1
fi
SRC_FOLDER="$1"
PKG_NAME=$(basename "$SRC_FOLDER")
WORKDIR=$(mktemp -d)
@davidel
davidel / curl_cd.md
Last active October 22, 2024 16:02
Curl And Circulation Density

Curl And Circulation Density

Given a vector $$\mathbb{R}^2$$ vector field:

$$\vec{F}\left( x , y \right) = M\left( x , y \right) \vec{i} + N\left( x , y \right) \vec{j}$$

Given a counter-clockwise rectangular curve in the $$\mathbb{R}^2$$ domain:

$$\left( x , y \right) \to \left( x + \Delta{x} , y \right) \to \left( x + \Delta{x} , y + \Delta{y} \right) \to \left( x , y + \Delta{y} \right) \to \left( x , y \right)$$

IMO 6th Question

Given $$a$$ and $$b$$ positive integers, every time $\left( a b + 1 \right)$ divides $a^2 + b^2$ the result is $$q \in \mathbb{N^+}$$ and $$q = s^2, s \in \mathbb{N^+}$$:

$$\frac{ a^2 + b^2 }{ a b + 1 } = q$$

Proof

Rewriting and expanding:

@davidel
davidel / pyexec.py
Last active October 7, 2024 05:59
Colab Write And Run
import IPython.core.magic as icm
@icm.register_cell_magic
def pyexec(line, cell):
path = line.split()[-1]
with open(path, mode='wt') as fd:
fd.write(cell)
get_ipython().run_line_magic('run', path)
import inspect
import sys
import types
def _fn_lookup(frame, name):
xns, xname = None, name
while True:
dpos = xname.find('.')
if dpos > 0:
#!/bin/bash
set -ex
HYFILE="$HOME/.bash_history"
TMPH=$(mktemp)
tac "$HYFILE" | awk '!x[$0]++' | tac > "$TMPH"
mv "$TMPH" "$HYFILE"
#!/bin/bash
set -ex
if [ ! -d ".git" ]; then
echo "Must be run from within a GIT repository!"
exit 1
fi
MAIN_BRANCH=$(git config --get init.defaultBranch || echo master)
import ast
import logging
import py_misc_utils.run_once as pyro
import py_misc_utils.utils as pyu
# Avoid dependency cycles ...
@pyro.run_once
def _lazy_import():