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
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
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
-- 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
""" | |
Python script that takes a folder, and for each CALS Raster file, it converts to a TIFF file. | |
https://en.wikipedia.org/wiki/CALS_Raster_file_format | |
file ending ".cal" | |
It so happens that TIFF can be compressed with Group 4 compression (as in faxes), and that is the compression format of CALS Raster images Type 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
class MemorizingNormalizer(nn.Module): | |
def __init__(self, d, eps, rho): | |
super().__init__() | |
self.means = nn.Parameter(torch.zeros(d), requires_grad=False) | |
self.vars = nn.Parameter(torch.ones(d), requires_grad=False) | |
self.eps = nn.Parameter(torch.tensor(eps, dtype=float), requires_grad=False) | |
self.rho = nn.Parameter(torch.tensor(rho, dtype=float), requires_grad=False) | |
def forward(self, x): | |
self.means.data = self.means * self.rho + (1 - self.rho) * x.mean(axis=0) |
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
# standards | |
from itertools import islice | |
import types | |
# 3rd party | |
import numpy as np | |
class RandomVariable(): | |
def __iter__(self): |
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
# standards | |
from abc import ABC | |
from itertools import islice | |
from collections import Counter | |
import types | |
# 3rd party | |
import numpy as np | |
import scipy.stats as stats | |
import matplotlib.pyplot as plt |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 urllib.request | |
import json | |
import typing | |
import functools | |
SEK = typing.NewType('SEK',float) | |
EUR = typing.NewType('EUR', float) | |
ConversionRate = typing.NewType('ConversionRate',float) | |
ThreeLetterCurrencyCode = str # ISO4217 |