Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
-- |
module Data.Torrent where
import Control.Applicative
import Control.Lens
import Data.AttoBencode
@reinh
reinh / tmp.hs
Last active August 29, 2015 14:03
data Thing = Thing
{ _foo :: Int
, _bar :: String }
buildFoo :: Other -> Thing
buildfoo = Thing <$> buildFoo
<*> buildBar
where buildFoo :: Other -> Int
buildFoo = undefined
buildBar :: Other -> String
class Renderable a where
render :: a -> IO ()
newtype Rectangle = Rectangle { width :: Double, height :: Double }
instance Renderable Rectangle where
render = undefined
newtype Circle = Circle { radius :: Double }
@reinh
reinh / Average.lhs
Last active January 4, 2016 07:18
Average Semigroup
=================
> {-# LANGUAGE GeneralizedNewtypeDeriving #-}
>
> module Average where
>
> import Data.Semigroup
> import Data.Ratio (Ratio, (%))
module ZSCII
( decode
, encode
) where
import Control.Applicative ((<$>), (<*>))
import Control.Monad ((<=<))
import Data.Binary.Put
import Data.Bits
import qualified Data.ByteString.Lazy as BL
@reinh
reinh / ZSCII.hs
Last active January 3, 2016 17:38
encode :: [Word8] => BL.ByteString
encode = runPut . putZSCII
putZSCII :: [Word8] -> Put
putZSCII zstring = do
mapM_
(putWord16be . encodeZchar)
(chunksOf 3 zstring)
putWord16be 0xb1000000000000000
nexts :: Game -> [Game]
nexts game
| isNothing (result game) = mapMaybe (update game) allMoves
| otherwise = []
type GameTree = Cofree [] Game
gameTree :: Game -> GameTree
gameTree = coiter nexts
@reinh
reinh / gist:8347685
Created January 10, 2014 06:11
Comma separated list in Haskell. Uses an Oxford comma as God intended.
oxfordian [] = ""
oxfordian [x] = x
oxfordian [x,y] = x ++ " and " ++ y
oxfordian [x,y,z] = x ++ ", " ++ y ++ ", and " ++ z
oxfordian (x:xs) = x ++ ", " ++ oxfordian xs
import Prelude hiding (length, replicate)
import Data.Vector hiding ((!), mapM_, take)
import qualified Data.Vector as V ((!?))
import Data.Monoid
type Cell = Char
type Universe = Vector Cell
size :: Int
size = 30

The organizer dedicated to changing the life of a particular community must first rub raw the resentments of the people of the community; fan the latent hostilities of many of the people to the point of overt expression. [They] must search out controversy and issues, rather than avoid them, for unless there is controversy people are not concerned enough to act.