Skip to content

Instantly share code, notes, and snippets.

Avatar

Sami Hangaslammi shangaslammi

  • Intopalo Oy
  • Tampere, Finland
View GitHub Profile
@shangaslammi
shangaslammi / Orbits.hs
Last active Dec 30, 2015
Orbital calculations
View Orbits.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE RecordWildCards #-}
module Orbits where
import Units
import Vec
data OrbitalElements
= OrbitalElements
@shangaslammi
shangaslammi / Dockerfile
Created Nov 27, 2013
centos6 Haskell container with GHC 7.6
View Dockerfile
FROM centos:6.4
# Install wget for fetching Haskell dependencies
RUN yum install -y wget
# Install dependencies for GHC and core Haskell libraries
RUN yum install -y libbsd-devel gmp-devel gmp zlib-devel
# Install tools needed for installing GHC and Cabal-install
RUN yum install -y make perl gcc
@shangaslammi
shangaslammi / Water.hs
Last active Dec 28, 2015
Recursive, single-pass, constant space solution to the watershed problem.
View Water.hs
import Data.Array
waterVolume :: Array Int Int -> Int
waterVolume arr = go 0 minB maxB where
(minB,maxB) = bounds arr
go !acc lpos rpos
| lpos >= rpos = acc
| leftHeight < rightHeight = segment leftHeight 1 acc lpos contLeft
| otherwise = segment rightHeight (-1) acc rpos contRight
View ConcurrencyExamples.hs
module ConcurrencyExamples where
import Control.Concurrent
import Control.Concurrent.STM
import Control.Monad
import Control.Applicative
import System.Random
example1 :: IO ()
example1 = do
@shangaslammi
shangaslammi / grunt.coffee
Created Oct 20, 2012
Common grunt-file template
View grunt.coffee
module.exports = (grunt) ->
grunt.initConfig
coffee:
compile:
files:
"public/js/modules/*.js": "src/coffee/**/*.coffee"
options:
flatten: false
bare: false
@shangaslammi
shangaslammi / hello-ski.hs
Created Aug 23, 2012
Hello World using SKI combinator calculus
View hello-ski.hs
s x y z = x z (y z)
k x y = x
i = s k k
c = s (s (k (s (k s) k)) s) (k k)
b = s (k s) k
hello =
s(s(k s)(s(k k)(s(k s)(s(k(s(k s)))(s(s(k s)(s(k k)(s(k b)i)))(k(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s
b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(c k))))))))))))))))))))))))))))))))))))))))))
)))))))))))))))))))))))))))(s(s(k s)(s(k k)(s(k s)(s(k(s(k s)))(s(s(k s)(s(k k)(s(k b)i)))(k(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s b(s
@shangaslammi
shangaslammi / Parser.hs
Created Mar 3, 2012
Example: parsing quoted strings with an applicative parser
View Parser.hs
quotedString :: Parser String
quotedString = char '"' *> many (escaped <|> nonQuote) <* char '"' where
escaped = char '\\' *> anyChar
nonQuote = charIf (/= '"')
@shangaslammi
shangaslammi / concatenative.hs
Created Feb 17, 2012
Concatenative Programming in Haskell
View concatenative.hs
{-# LANGUAGE TypeOperators, NoImplicitPrelude #-}
import qualified Data.List as L
import Control.Arrow
import Control.Monad
import Prelude (Bool, Int, Float, fst, snd, flip, ($), uncurry, Show(..), String, (.), otherwise, IO)
import qualified Prelude as P
data s :. a = !s :. !a
infixl 1 :.
@shangaslammi
shangaslammi / dsl-example.hs
Created Jan 26, 2012
Digraph template-DSL example
View dsl-example.hs
{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
import Data.Graphs.DSL.TH
thExample = [digraph|
a
b -> c
e <-> c
|]
@shangaslammi
shangaslammi / CustomShow.hs
Created Dec 27, 2011
Template Haskell Example
View CustomShow.hs
{-# LANGUAGE TemplateHaskell, FlexibleInstances #-}
module CustomShow where
import Language.Haskell.TH
import Data.List (intercalate)
emptyShow :: Name -> Q [Dec]
emptyShow name = [d|instance Show $(conT name) where show _ = ""|]