Skip to content

Instantly share code, notes, and snippets.

View andreasWallner's full-sized avatar

Andreas Wallner andreasWallner

  • private
  • Austria
View GitHub Profile
@andreasWallner
andreasWallner / crc.py
Created August 24, 2021 23:59
Simple CRC toy examples to try to figure out parameters of the one used in ISO 14443
def str2int(s):
i = 0
for c in s:
i = (i << 1) + (1 if c == '1' else 0)
return i
def xor(a, b):
return ['1' if aa != bb else '0' for aa, bb in zip(a, b)]
def inv(a):
{
"cells": [
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
@andreasWallner
andreasWallner / logging.md
Last active April 24, 2023 05:29
a few notes about logging in python

Python Logging

notes about logging in python. Put together from reading the logging module source, PEP 282, the official documentation, as well as the blog entries mentioned in References.

Its just intended to collect some notes in one place...so it will (most likely) never comprehensive.

Basic Usage

@andreasWallner
andreasWallner / lsfr.py
Created June 12, 2014 22:12
Galois LSFR implementation for python
""" simple LFSR generator
Uses galois algorithmn to return next bit of LFSR.
To initialize the generator pass the seed value (one
value that the generator will generate, != 0) and
the used polynom.
Observe that for a n bit polynom, x^n has to be in
the polynom, which should be the case anyhow therefore e.g.:
x^4 + x^3 + 1 = 0b1100
@andreasWallner
andreasWallner / Dynamic cast benchmark.md
Last active May 14, 2023 18:19
A short benchmark of dynamic_cast

Topic

After a discussion about the performance implications of dynamic_cast, I had some time on my hands and wanted to check it myself (at least to some degree). That prompted the measurements below, where dynamic_cast is compared against an implementation that uses class member that cary an unique identifier to check. The functionality of the implementation is not the same as with dynamic_cast, but it satisfies the application that was discussed:

class Base {
@andreasWallner
andreasWallner / imgconv.py
Last active August 11, 2022 05:20
Simple python module to put images into C arrays (converted to 4 color greyscale). The array can be used to put the image onto e.g. a LCD screen.
""" simple script to convert image into c array
Image is converted into a 4 color greyscale image
and then exported as a space-optimized array.
The exact format can be found at the end of the
file as it is printed as a comment into the resulting
C file.
"""
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
@andreasWallner
andreasWallner / latex_lenght_conversion.tex
Last active August 29, 2015 13:57
LaTeX: print out lengths, converted into other units
% version using the layout package
\usepackage{layout}
\printinunitsof{cm}\prntlen{\textwidth} \prntlen{\textheight}
% Snippet by junanjo from www.latex-community.org (http://www.latex-community.org/forum/viewtopic.php?f=5&t=2712)
\usepackage{fp}
\newlength{\TOarg} \newlength{\TOunit}
{\catcode`p=12 \catcode`t=12 \gdef\TOnum#1pt{#1}}
import numpy as np
mu_0 = 4 * np.pi * 10e-7
def field_contribution(x, y, pos, I, r):
v = np.asarray([x,y])
v = v - pos
if np.abs(np.sum(v*v)) < r*r:
return np.asarray([0,0])
factor = mu_0 / (2 * np.pi * np.dot(v,v))
@andreasWallner
andreasWallner / 50-pycalc.py
Last active March 2, 2023 20:38
simple magic that enables better use of ipython as a calculator
""" PyCalc
A small "package" that makes it easier for engineers to use IPython as a calculator.
The idea is to extend the python syntax to understand the SI prefixes that are
customary in engineering, like "milli" or "Mega". The code below registers a
TokenInputTransformer with IPython that will rewrite every python line before
it is given to python itself.
It also changes the IPython output routines so that the same prefixes are also