Skip to content

Instantly share code, notes, and snippets.

View shangaslammi's full-sized avatar

Sami Hangaslammi shangaslammi

  • Infer Oy
  • Tampere, Finland
  • 10:35 (UTC +02:00)
View GitHub Profile
@shangaslammi
shangaslammi / Orbits.hs
Last active December 30, 2015 17:39
Orbital calculations
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE RecordWildCards #-}
module Orbits where
import Units
import Vec
data OrbitalElements
= OrbitalElements
@shangaslammi
shangaslammi / Dockerfile
Created November 27, 2013 08:19
centos6 Haskell container with GHC 7.6
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 December 28, 2015 00:18
Recursive, single-pass, constant space solution to the watershed problem.
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
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 October 20, 2012 16:57
Common grunt-file template
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 August 23, 2012 16:53
Hello World using SKI combinator calculus
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 March 3, 2012 20:56
Example: parsing quoted strings with an applicative parser
quotedString :: Parser String
quotedString = char '"' *> many (escaped <|> nonQuote) <* char '"' where
escaped = char '\\' *> anyChar
nonQuote = charIf (/= '"')
@shangaslammi
shangaslammi / concatenative.hs
Created February 17, 2012 06:01
Concatenative Programming in Haskell
{-# 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 January 26, 2012 16:26
Digraph template-DSL example
{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
import Data.Graphs.DSL.TH
thExample = [digraph|
a
b -> c
e <-> c
|]
@shangaslammi
shangaslammi / CustomShow.hs
Created December 27, 2011 19:59
Template Haskell Example
{-# 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 _ = ""|]