This file contains 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
#!/bin/bash | |
mediainfo "$1" | grep "Bit rate" |
This file contains 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 Lenses where | |
import Prelude hiding ((.), id) | |
import Control.Category | |
data Lens s a = Lens (s -> a) ((a -> a) -> s -> s) | |
instance Category Lens where | |
id = Lens id id | |
(Lens lg lm) . (Lens rg rm) = Lens (lg . rg) (rm . lm) |
This file contains 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 Alloc where | |
import Control.Arrow (first) | |
import Data.List (mapAccumL) | |
{- | |
given a stream of [[Int]] each sublist representing a day, each place representing people | |
each number representing the number of days they want to stay | |
We would like to get a list of rooms to check in on the day and rooms to check out on the day | |
and maximum number of occupied rooms. |
This file contains 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
{- | |
problem: generate infinite list of triples by height, i.e.: | |
[(1,1,1), (1,1,2), (1,2,1), (2,1,1), (1,1,3), ... ] | |
-} | |
import Data.List (nub, inits) | |
-- inefficient (exponential): | |
triples :: Int -> [(Int, Int, Int)] |
This file contains 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 Schools where | |
import Data.List (elemIndex) | |
{- | |
Problem: | |
- for every chilld rank all schools | |
- for every school, rank every child | |
- specify capacity of every school (Pupil Allocation Number) |
This file contains 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
-- this runs pretty nicely with +RTS -N2 | |
import Control.Concurrent.STM (atomically, STM) | |
import Control.Concurrent.STM.TQueue (TQueue, newTQueueIO, tryReadTQueue, writeTQueue) | |
import Control.Concurrent (forkIO) | |
import Control.Monad (forever, forM_, when) | |
import Graphics.UI.WX hiding (when) | |
-- Graphics.UI.WX.Async |
This file contains 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 Logger where | |
import System.IO | |
type Logger = String -> IO () | |
data Logging a = Logging { unLogging :: Logger -> IO a } | |
logLine :: String -> Logging () | |
logLine s = Logging $ \l -> l s |
This file contains 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 TypeSynonymInstances, FlexibleInstances, DeriveDataTypeable #-} | |
module Traverse where | |
import Data.Data | |
import Data.Generics.Aliases | |
import Data.Typeable | |
data Tree a = Node a [Tree a] | |
deriving (Show, Data, Typeable) |
This file contains 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 ViewPatterns, GADTs, KindSignatures #-} | |
import Data.List | |
{- | |
catamorphisms: folds | |
anamorphisms: unfolds | |
foldr vs foldl: foldl is almost never the right thing to use, use foldl' instead, which is a strict version | |
(optimiser will do this for us) | |
-} |
This file contains 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 Puzzle where | |
import Data.List | |
data Girl = Ellie | Emily | Jessica deriving (Bounded, Enum, Eq, Show) | |
data Animal = Elephant | Zebra | Giraffe deriving (Bounded, Enum, Eq, Show) | |
data Lolly = Grunge | Plooper | Zinger deriving (Bounded, Enum, Eq, Show) | |
data Adult = Aunt | Grandma | Mum deriving (Bounded, Enum, Eq, Show) |