Skip to content

Instantly share code, notes, and snippets.

Jan Weidner jw3126

  • Freiburg, Germany
Block or report user

Report or block jw3126

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
jw3126 / Interpreter.hs
Last active Aug 5, 2017
Interpreter in haskell that can store and retrieve variables
View Interpreter.hs
import Data.Map as Map
import Data.Map
import Control.Monad.State.Lazy
import Control.Monad
data Expr = ExInteger Integer
| ExSymbol String
| ExBinding String Expr deriving (Show)
type Errorful t = Either String t
jw3126 / supress.hs
Created Aug 6, 2017
Mapping from IO type to a "pure" type
View supress.hs
-- we can define functions that discard IO
io :: IO Int
io = print "wehaa" >> return 17
supress :: IO Int -> Int
supress _ = 42
supress io
jw3126 / SIMDmedian.jl
Last active Oct 13, 2017
SIMD median
View SIMDmedian.jl
using SIMD
Base.@pure simdwidth(::Type{T}) where {T} = Int(256/8/sizeof(T))
@inline function median3(a,b,c)
max(min(a,b), min(c,max(a,b)))
@inline function median5(a,b,c,d,e)
View macrohygiene.jl
module M
export @esc_none, @esc_all, @esc_args, @esc_args_impl
macro esc_none(x, y)
macro esc_all(x,y)
jw3126 / reactive.jl
Created Nov 17, 2017
implement functional reactive programming in julia
View reactive.jl
import Base: map, push!, reduce, mapreduce
type Stream{T}
function Stream(startvalue, update_rule=self -> nothing, subscribers=[])
T = typeof(startvalue)
jw3126 /
Created Apr 20, 2018
Simple lifetime example
use std::path::{Path};
fn create_path<'a>(s: &'a String)->&'a Path { // return value has the same lifetime as input
fn main() {
let s = "some/path".to_string();
let p = create_path(&s);
jw3126 / temporary value does not live long
Created May 17, 2018
temporary value does not live long enough
View temporary value does not live long
struct MyString {
impl MyString {
fn to_str(&self) -> &str {
jw3126 / klein_nishina.jl
Last active Nov 8, 2019
Klein-Nishina formula
View klein_nishina.jl
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
View gist:ca1ed1a7f62a059849b15a8b538031a0
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 / so3.jl
Created Oct 5, 2018
Haar Measure of distance Ball SO(3)
View so3.jl
using StatsBase
using LinearAlgebra
using StatPlots
using Plots
using Rotations
function sample_angles(N)
map(1:N) do _
You can’t perform that action at this time.