Skip to content

Instantly share code, notes, and snippets.

View dermesser's full-sized avatar
🐢
a bit of time :-)

Lewin Bormann dermesser

🐢
a bit of time :-)
View GitHub Profile
@dermesser
dermesser / STM.jl
Last active April 2, 2021 21:32
Simulation of a Scanning Tunneling Microscope's control algorithm (Pluto notebook)
### A Pluto.jl notebook ###
# v0.12.21
# (c) 2021 Lewin Bormann
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
@dermesser
dermesser / linreg.jl
Created March 16, 2021 10:43
Some handy utilities for calculating and drawing linear regressions in Julia, including residual analysis.
import LsqFit
import Plots
function fwhm(sigma::Real)::Float64
# Calculate FWHM from sigma.
2sqrt(2log(2))*sigma
end
const M64 = Measurements.Measurement{Float64}
@dermesser
dermesser / radon.py
Created March 16, 2021 09:46
Radon transform: Sampling and reconstruction
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 13 19:26:59 2021
@author: lbo
"""
import numpy as np
from numpy import fft
@dermesser
dermesser / mlmagic.cc
Last active January 14, 2021 21:33
Use a Kernel Ridge Regression to classify Pion vs. Proton events in a (fictional?) detector.
/*
* To run, install BLAS, LAPACK, and DLib, then do this:
*
* $ g++ -l:libcblas.so.3 -l:liblapack.so.3 -ldlib mlmagic.cc -o run && ./run
*
* If it doesn't work, fiddle with the -l options and ensure that you have the right libraries installed.
*
* This file is very very roughly modeled after the DLib example for Kernel Ridge Regression:
* http://dlib.net/krr_classification_ex.cpp.html
*/
@dermesser
dermesser / simplesexpr.py
Created December 10, 2020 13:27
A naive S-expr parser in python
#!/usr/bin/env python3
# Simple sexpr parser
from collections import namedtuple
Expr = namedtuple('Expr', ('children'));
OPEN = 1
CLOSE = 2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 1 12:12:22 2020
@author: lbo
"""
import numpy as np
import matplotlib.pyplot as plt
@dermesser
dermesser / harmonic_oscillator_phasespace_animate.py
Last active December 2, 2020 17:53
Animating phase space movement in a 1D harmonic oscillator: https://youtu.be/v4edySA8Gzk (contains numeric friction)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 1 12:12:22 2020
@author: lbo
"""
import numpy as np
import matplotlib.pyplot as plt
@dermesser
dermesser / linear_box_phasespace.py
Last active December 2, 2020 17:53
RWTH Theoretische Physik IV WS 20/21 ÜB 5 A2 a). Outputs to MP4. (https://youtu.be/2pKO514cMNU)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 1 12:12:22 2020
Run: $ python a2a.py
Writes to `animation.mp4`. Adjust parameters below.
@author: lbo
"""
@dermesser
dermesser / onedim_gas.py
Last active November 22, 2020 12:40
This event-based simulation simulates a 1-dimensional gas: https://borgac.net/~lbo/8particles_1000.svg
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 21 20:04:54 2020
@author: lbo
"""
from recordtype import recordtype
from queue import PriorityQueue
TokenStream [Ident { ident: "test_function_onearg", span: #0 bytes(437..457) }, Group { delimiter: Parenthesis, stream: TokenStream [Literal { kind: Integer, symbol: "32", suffix: None, span: #0 bytes(458..460) }], span: #0 bytes(457..461) }]
thread 'rustc' panicked at 'expected one of: `for`, parentheses, `fn`, `unsafe`, `extern`, identifier, `::`, `<`, square brackets, `*`, `&`, `!`, `impl`, `_`, lifetime', /home/lbo/.cargo/registry/src/github.com-1ecc6299db9ec823/syn-1.0.48/src/parse_quote.rs:95:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md