This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- we can define functions that discard IO | |
io :: IO Int | |
io = print "wehaa" >> return 17 | |
supress :: IO Int -> Int | |
supress _ = 42 | |
supress io |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) | |
end | |
@inline function median5(a,b,c,d,e) | |
# https://stackoverflow.com/questions/480960/code-to-calculate-median-of-five-in-c-sharp | |
f=max(min(a,b),min(c,d)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module M | |
export @esc_none, @esc_all, @esc_args, @esc_args_impl | |
macro esc_none(x, y) | |
impl(x,y) | |
end | |
macro esc_all(x,y) | |
esc(impl(x,y)) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug)] | |
struct MyString { | |
s:String, | |
} | |
impl MyString { | |
fn to_str(&self) -> &str { | |
&self.s | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 _ |
OlderNewer