Skip to content

Instantly share code, notes, and snippets.

View tippenein's full-sized avatar

Brady Ouren tippenein

  • Los Angeles, CA
  • 04:41 (UTC -07:00)
View GitHub Profile
@tippenein
tippenein / nub_spaces.hs
Created September 6, 2016 22:37
comfy?
import Data.List (intercalate)
import Data.List.Split (splitOn)
nub_spaces :: String -> String
nub_spaces = splitOn " " |> filter (/= "") |> join " "
(|>) = flip (.)
join = intercalate
main = do
@tippenein
tippenein / naive_timer.hs
Last active August 23, 2016 03:30
naive timer
import Text.Parsec
type Parser = Parsec String ()
data T = T { hours :: Int, minutes :: Int, seconds :: Int }
instance Show T where
show (T h m s) = show h ++ " hours " ++ show m ++ " minutes " ++ show s ++ " seconds"
parse' :: Parser a -> String -> Either ParseError a
@tippenein
tippenein / blog.elm
Created August 5, 2016 05:29
pieces of an elm example
type Action
= FetchDocuments
| ErrorOccurred String
| DocumentsFetched (List Document)
model : Model
model =
{ documents = Right []
, queryString = ""
}
type alias Person =
{ name : String
}
type alias Model =
{ persons : List Person
}
model : Model
model =
@tippenein
tippenein / encoding.hs
Last active June 18, 2016 21:07
json encoding example
#!/usr/bin/env runhaskell
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Aeson as Aeson
import Data.Text
import Data.Time.Clock
import GHC.Generics
import Text.Printf
import Data.List
data P = P (Double, Double) deriving (Ord, Show, Eq)
class Geom a where
sub :: a -> a -> a
crossProduct :: a -> a -> Double
distance :: a -> a -> Double
λ: import Control.Lens
λ: :t _1
_1 :: (Functor f, Field1 s t a b) => (a -> f b) -> s -> f t
λ: :t _2
_2 :: (Functor f, Field2 s t a b) => (a -> f b) -> s -> f t
λ: :i Getting
type Getting r s a = (a -> Const r a) -> s -> Const r s
-- Defined in ‘Control.Lens.Getter’
λ: view _2 (1,2)
2
@tippenein
tippenein / roman_translation.hs
Created June 4, 2016 23:19
Not sure where this problem came from, but it was in an old folder
import Control.Monad
romanValues = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
romanDigits = words "m cm d cd c xc l xl x ix v iv i"
theRomans = zip romanValues romanDigits
toRoman' :: Int -> String
toRoman' n = fst $ foldl romFold ("", n) theRomans
romFold :: ([a], Int) -> (Int, [a]) -> ([a], Int)
import Control.Parallel
import Data.Monoid
data Collection = Collection
{ s :: Integer
, average :: Double
, count :: Integer
}
deriving (Show)
@tippenein
tippenein / regex.hs
Created May 31, 2016 01:26
an incomplete regex implementation (moved from old repo)
-- regex implementation
module Main where
import Control.Exception
import Prelude hiding (max,min)
data Atom = Literal Char
| OneOf String
| NoneOf String