Skip to content

Instantly share code, notes, and snippets.

@erantapaa
erantapaa / setup-tuf.sh
Created August 27, 2015 15:27
Setting up keys for a new hsackage-server
#!/bin/sh
#
# Script to populate a TUF directory with a new set of private keys.
#
# Note: Need to install the hackage-repo-tool package from Hackage.
REPO_TOOL=hackage-repo-tool
KEYS_DIR=/tmp/keys
DATA_DIR=./datafiles
@erantapaa
erantapaa / gist:69fa2c060f67d74e477a
Created December 15, 2014 16:28
Timing subsequencesOfSize
import System.TimeIt
import System.Environment
import Text.Printf
subsequencesOfSize1 :: Int -> [a] -> [[a]]
subsequencesOfSize1 n xs = let l = length xs
in if n>l then [] else subsequencesBySize xs !! (l-n)
where
subsequencesBySize [] = [[[]]]
subsequencesBySize (x:xs) = let next = subsequencesBySize xs
@erantapaa
erantapaa / gist:82b59282dee72347efc2
Last active August 29, 2015 14:11
building gtk 2.x on OSX for Haskell

Check list for installing gtk 2.x for Haskell on OSX:

  1. Install XQuartz (link) - this is needed for the xcb-shm package config file.
  2. brew install gtk+
  3. export PKG_CONFIG_PATH=/usr/local/Cellar/cairo/(...whatever...)/lib/pkgconfig:/opt/X11/lib/pkgconfig/:
  4. Make sure alex and happy are installed - they are needed by gtk2hs-buildtools
  5. cabal install gtk2hs-buildtools
  6. cabal install gtk
@erantapaa
erantapaa / p8.hs
Created January 14, 2015 05:37
implementing sequencePipes
import System.Environment
import qualified Data.Array as A
import Data.Array.IO
import qualified Data.Array.MArray as M
import Data.Array.Base ( UArray, unsafeFreezeSTUArray )
import Data.Array.Unboxed
import qualified Data.Array.Unboxed as U
import Control.Monad
import Debug.Trace
import Pipes
@erantapaa
erantapaa / e14.hs
Created January 15, 2015 04:05
euler #14 collatz problem
{-# LANGUAGE BangPatterns #-}
import Data.Array.IO
import Data.Array.Unboxed
import Control.Monad
collatz x
| even x = div x 2
| otherwise = 3*x+1
@erantapaa
erantapaa / gauss.hs
Created January 17, 2015 03:47
solution to 1had "Let it snow" http://lpaste.net/118571
-- Solution to "Let it snow" 1had - http://lpaste.net/118571
import qualified Data.Map.Strict as M
import Data.List
import Control.Monad
import Data.Maybe
data SnowFlake = Six | Star | Eight | Flower | Unit
deriving (Eq, Ord, Show)
@erantapaa
erantapaa / example.hs
Created January 27, 2015 18:14
embed svg diagram in html using blaze
{-# LANGUAGE OverloadedStrings #-}
import Text.Blaze.Svg11 ((!), mkPath, rotate, l, m)
import qualified Text.Blaze.Svg11 as S
import qualified Text.Blaze.Svg11.Attributes as A
import Text.Blaze.Svg.Renderer.String (renderSvg)
import qualified Text.Blaze.Html5 as H
import Text.Blaze.Html.Renderer.Text
import qualified Data.Text.Lazy.IO as TL
main :: IO ()
@erantapaa
erantapaa / cabal.config
Created February 2, 2015 20:10
hackage versions as of 2012-05-23 UTC
-- Hackage versions as of 2012-05-23 00:00:00 UTC
constraints:
4Blocks <= 0.2,
AC-Angle <= 1.0,
AC-Boolean <= 1.1.0,
AC-BuildPlatform <= 1.1.0,
AC-Colour <= 1.1.4,
AC-EasyRaster-GTK <= 1.1.3,
AC-HalfInteger <= 1.2.1,
AC-MiniTest <= 1.1.1,
#!/bin/sh
#
# Recipe for reproducing a linkage error with GHC 7.8.3 under OSX.
#
# GHC was installed using https://ghcformacosx.github.io/
#
# Specific 7.8.3 version: https://github.com/ghcformacosx/ghc-dot-app/releases/download/v7.8.3-r1/ghc-7.8.3-r1.zip
#
# Output of the find command at the end will include a reference to 'findExecutable3_info',
# but nowhere does the tar package reference the function 'findExecutable'.
@erantapaa
erantapaa / hackage-server-build-notes
Last active August 29, 2015 14:14
building hackage-server
Currently hackage-server only builds with GHC 7.6.3.
# Installing ghc 7.6.3 for OSX
# download the GHC 7.6.3 tarball for OSX (64-bit)
# for links to other OSes: https://www.haskell.org/ghc/download_ghc_7_6_3
wget https://www.haskell.org/ghc/dist/7.6.3/ghc-7.6.3-x86_64-apple-darwin.tar.bz2
tar jxf ghc-7.6.3-x86_64-apple-darwin.tar.bz2
cd ghc-7.6.3
mkdir $HOME/apps