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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 30 13:17:31 2019
@author: Bormann, Lewin; Jürgens, Kira; Leung, Emily
"""
import random
@dermesser
dermesser / gasapproximation.py
Last active May 11, 2019 08:58
Calculates point until which ideal gas calculations are accurate to within one percent for various gases. https://physikmix.lewinb.net for more!
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat May 4 11:36:15 2019
Results for:
He - 1.015 MPa (+/- 0.99%)
CO2 - 191.754 kPa (+/- 1%)
N2 - 1.002 MPa (+/- 0.99%)
@dermesser
dermesser / spinner.py
Last active May 11, 2019 16:22
Spinner movement calculations, numerically! Example plot: http://physikmix.lewinb.net/pdf/spinnerplot1.pdf
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Spinner movement equations solved numerically
@author: lbo
"""
import matplotlib.pyplot as plt
@dermesser
dermesser / heapsort.rs
Created June 2, 2019 09:10
Simple, but surprisingly fast heapsort implementation
#[macro_use]
extern crate time_test;
use std::cmp::PartialOrd;
fn left(i: usize) -> usize {
2 * i + 1
}
fn right(i: usize) -> usize {
2 * i + 2
@dermesser
dermesser / coaches.c
Created July 30, 2019 15:17
counting coaches in a circular train!
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct coach;
struct coach {
struct coach* prev;
struct coach* next;
@dermesser
dermesser / intensity.lisp
Created October 12, 2019 11:02
Calculate how much intensity is left after polarizing unpolarized light
;; Calculate intensity of polarized light
(defun norm (v) (sqrt (reduce (lambda (a e) (+ a (expt e 2))) v :initial-value 0)))
(defun make-ray (x y) (vector x y))
(defun deg-to-rad (deg) (* PI (/ deg 180)))
(defun random-normed-ray (&optional (max 100))
(flet ((random-component () (/ (1+ (random (1- max))) max)))
@dermesser
dermesser / nbody.lisp
Created October 15, 2019 16:41
A simple numeric n-body simulation generating CSV data for plotting. Best used interactively!
;; Calculate 3-body problem (later: generalize to n-body)
;; General helpers
(defun unique-pairs (up-to)
"Generate all unique combinations of numbers from 0 to up-to - 1 without (n,n) pairs. I.e., (1,2), (1, 3), ..., (2, 3), (2, 4), ..."
(let ((result '()))
(loop for i from 0 to (1- up-to) do
(loop for j from (1+ i) to (1- up-to) do
(push (list i j) result)))
@dermesser
dermesser / fastcgi-server.service
Created February 15, 2020 18:29
FastCGI config in purely systemd: This works for services expecting a socket on stdin, like HG Web (see example)
[Unit]
Wants=network.service nginx.service
[Install]
Alias=hgweb
WantedBy=multi-user.target
[Service]
User=lbo
Type=exec
ExecStart=/home/lbo/hg/.config/hgweb.fcgi
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
@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