Skip to content

Instantly share code, notes, and snippets.

View jw3126's full-sized avatar

Jan Weidner jw3126

  • Freiburg, Germany
View GitHub Profile
@jw3126
jw3126 / DirichletAnnulusApproxFun.jl
Last active January 23, 2019 08:17
DirichletAnnulusApproxFun.jl
using ApproxFun
using LinearAlgebra
using Interact
using Plots
a = 1.; b=5.
Ω = a..b
# Ω = Chebyshev(a..b)
r = Fun(identity, Ω)
Δ_rad = 𝒟^2 + 1.0/r * 𝒟
@jw3126
jw3126 / MakieSphericalHarmonics.jl
Created January 12, 2019 22:36
MakieSphericalHarmonics
using GSL
using Makie
struct Y
l::Int
m::Int
function Y(l,m)
@assert -l <= m <= l
new(l,m)
end
@jw3126
jw3126 / egs_parallel.sh
Created November 30, 2018 12:13
egs parallel
# install egs
# make tutor2pp
sudo apt install at
exb tutor2pp test1 tutor_data p=42
@jw3126
jw3126 / install.sh
Created November 12, 2018 10:23
Install EGSnrc
#!/bin/bash
###### tweakable parameters
EGS_SRC=$HOME/EGSnrc
CONFIG=linux.conf
COMPILE_USER_CODES=1
###### script implemention
export HEN_HOUSE=$EGS_SRC/HEN_HOUSE
export EGS_CONFIG=$HEN_HOUSE/specs/linux.conf
@jw3126
jw3126 / so3.jl
Created October 5, 2018 12:51
Haar Measure of distance Ball SO(3)
# https://math.stackexchange.com/questions/1049788/haar-measure-of-an-angle-distance-ball-in-so3
using StatsBase
using LinearAlgebra
using StatPlots
using Plots
using Rotations
function sample_angles(N)
map(1:N) do _
@jw3126
jw3126 / gist:ca1ed1a7f62a059849b15a8b538031a0
Last active September 27, 2018 20:11
projected move regression
using LinearAlgebra
function linreg(xs, ys)
# Axs + b ≈ ys
@assert size(xs,2) == size(ys,2)
nobs = size(xs, 2)
xs_ = [xs; transpose(ones(nobs))]
ys_ = [ys; transpose(ones(nobs))]
A_ = ys_ / xs_
@assert A_[end, end] 1
@jw3126
jw3126 / klein_nishina.jl
Last active December 12, 2020 09:04
Klein-Nishina formula
using Unitful
using Unitful: MeV, NoUnits, cm
using UnitfulRecipes
const h = 6.626_070_040e-34*u"J*s"
const h_bar = h / (2pi)
const m_e = 9.10938356e-31 * u"kg"
const c = 299_792_458.0 * u"m/s"
const r_c = h_bar / (c*m_e) # reduced compton wavelength of electron
@jw3126
jw3126 / temporary value does not live long enough.rs
Created May 17, 2018 14:04
temporary value does not live long enough
#[derive(Debug)]
struct MyString {
s:String,
}
impl MyString {
fn to_str(&self) -> &str {
&self.s
}
@jw3126
jw3126 / lifetime.rs
Created April 20, 2018 11:51
Simple lifetime example
use std::path::{Path};
fn create_path<'a>(s: &'a String)->&'a Path { // return value has the same lifetime as input
Path::new(s)
}
fn main() {
let s = "some/path".to_string();
let p = create_path(&s);
@jw3126
jw3126 / reactive.jl
Created November 17, 2017 20:56
implement functional reactive programming in julia
import Base: map, push!, reduce, mapreduce
type Stream{T}
value::T
update_rule::Function
subscribers::Vector{Stream}
end
function Stream(startvalue, update_rule=self -> nothing, subscribers=[])
T = typeof(startvalue)