Skip to content

Instantly share code, notes, and snippets.

View simonh1000's full-sized avatar

Simon Hampton simonh1000

View GitHub Profile
@simonh1000
simonh1000 / miu.hs
Last active August 29, 2015 14:03
MIU puzzle in Haskell
import Data.List
import Text.Regex.Posix
rule :: Int -> String -> ((String, String, String, [String]) -> String) -> ([Int],String) -> ([Int],String)
rule x pat f (routes,s) =
let
res = s =~~ pat :: Maybe (String, String, String, [String])
in case res of
Just r -> (x:routes, f r)
Nothing -> (routes,[])
@simonh1000
simonh1000 / mst.hs
Created July 2, 2014 08:49
Haskell Max Spanning Tree implementation
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector as V
import qualified Data.List as L
import qualified Data.Heap as H
import qualified Data.IntSet as S
type Node = Int
type Cost = Int
data Edge = Edge Node Cost deriving (Eq, Show)
type Edges = [Edge]
@simonh1000
simonh1000 / app.html
Last active August 29, 2015 14:05
Polymer tabbed SPA
<!doctype html>
<html>
<head>
<title>AF Mobile polymer</title>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<script src="./bower_components/platform/platform.js"></script>
@simonh1000
simonh1000 / qsort.hs
Created October 26, 2014 08:17
QuickSort using mutable STArray
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import Data.Array
qsort :: (STArray s Int Int) -> Int -> Int -> ST s ()
qsort arr min mx =
if mx - min < 1 then
@simonh1000
simonh1000 / Maybe.class.js
Created January 4, 2015 19:41
Maybe Monad in Javascript
"use strict"
/*
An implementation of the Maybe monad in ES6, representing
- Maybe as a singleton array
- Nothing and null
Compiled and run with Traceur
traceur --out build.js --script maybe.js
@simonh1000
simonh1000 / functor-monad.hs
Last active August 29, 2015 14:13
Functor < Applicative < Monad - demonstration of the hierarchy of type Classes
import Control.Applicative
import Control.Monad
-- :k MonadClass :: * -> *
data MonadClass a = MonadClass a
-- fmap :: (a -> b) -> (m a -> m b)
instance Functor MonadClass where
fmap f = (<*>) (MonadClass f)
@simonh1000
simonh1000 / main.elm
Created September 22, 2015 14:10
Elm: Download Json with error handling
import Http
import Markdown
import Html exposing (Html, div, text)
import Task exposing (Task, andThen)
import Json.Decode as Json exposing (..)
type alias ValWithErr = Result String Int
main : Signal Html
main =
@simonh1000
simonh1000 / Main.elm
Last active October 14, 2015 12:33
Elm 'SPA' with Google Maps on second page
module Spa where
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import StartApp
import Effects exposing (Effects, Never)
import Task
@simonh1000
simonh1000 / Main.elm
Last active July 7, 2016 12:13
Form errors
module Test exposing (..)
import Platform.Cmd exposing (Cmd)
import Html exposing (..)
import Html.App as Html
import Html.Attributes exposing (..)
import Form exposing (..)
import Form.Input as Input
module Test exposing (..)
import Html exposing (..)
import Html.App as App
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import List exposing (map)
import Json.Decode as Json