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
-- Inspired by https://stackoverflow.com/questions/17719620/while-loop-in-haskell-with-a-condition | |
import Control.Monad.State | |
type IsZero = Bool | |
{- | |
This is in State monad. I.e. it is a function, that when given an initial state (Int,IsZero) will produce a tuple of ((Int,IsZero),()) | |
We can see this as an action on our state space with no output value. | |
-} |
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 RPG where | |
import Text.Read (readMaybe) | |
type UIState = String | |
data Domain = Domain (UIState,World) deriving Show | |
data World = World {loc:: Int} deriving Show | |
data Dir = L | R deriving (Read, Show) | |
{- | By using the "deriving (Read)" we get a low-code input mechanism, but you should probalbly write | |
your own input parser | |
-} |
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
WIDTH = 100 | |
HEIGHT = 100 | |
DURATION = 1 # seconds | |
FRAMES = 25*DURATION | |
def rgb2ycrcb(r,g,b): | |
""" ITU-R BT.601 (formerly CCIR 601) transformation | |
input in range 0-255 | |
output in range 16-235 (headroom/footroom) for Y' | |
output in range 16-240 (headroom/footroom) for Cr/Cb |
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
-- first monoid over Floats | |
data MaxNum = MaxNum Float deriving (Show) | |
instance Semigroup MaxNum where | |
(MaxNum a) <> (MaxNum b) = MaxNum $ max a b | |
instance Monoid MaxNum where | |
mempty = MaxNum 0 -- N.B. this does not fulfil the monoid laws fully. consider negative values! | |
aOne = MaxNum 4 | |
aTwo = MaxNum 1 | |
aThree = aOne <> aTwo |
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
# %% set up the plot | |
import matplotlib.pyplot as plt | |
import numpy as np | |
from matplotlib.widgets import Slider | |
LOC_MAX = 2 | |
# The parametrized function to be plotted | |
def f1(t, amplitude, location): |
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 System.IO.Unsafe ( unsafeInterleaveIO ) | |
import System.Random ( randomRIO ) | |
import Text.Printf ( printf ) | |
-- | An infinite list of random die rolls, lazily generated | |
-- | |
-- This is dangerous since calling this function steps the global random generator | |
-- not when running the action, but when accessing its result. | |
diceRolls :: IO [Int] | |
diceRolls = do |
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
""" | |
Comparison of empirical bernstein measures | |
See https://el-hult.github.io/2022/03/18/empirical-bernstein-bounds.html | |
""" | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import scipy.stats as sps | |
import pandas as pd |
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 numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib.patches import Ellipse, Rectangle | |
from matplotlib.transforms import Affine2D | |
from scipy.stats import t, f | |
from scipy.linalg import sqrtm | |
import statsmodels.api as sm | |
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
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE KindSignatures #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
module Pointers where | |
import Data.Proxy (Proxy (..)) | |
import Foreign.Marshal.Array (newArray, peekArray) | |
import Foreign.Ptr (Ptr) | |
import GHC.TypeNats (KnownNat, Nat, natVal) |
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
# nice library that gives us access to the microphone | |
import pyaudio | |
# python standard libraries that come built-in | |
import threading | |
import queue | |
import wave | |
# optional libraries | |
import numpy as np |