Skip to content

Instantly share code, notes, and snippets.

View nh2's full-sized avatar

Niklas Hambüchen nh2

View GitHub Profile
@nh2
nh2 / relaxation-labelling.hs
Last active December 29, 2015 07:19
Relaxation labelling in Haskell
-- Relaxation labelling in Haskell
-- Usage: Load it in ghci, type `step 2` for 2 iterations.
import Data.List.Split (chunksOf)
import Text.Printf (printf)
import qualified Data.MemoCombinators as Memo -- data-memocombinators
import Data.MemoCombinators (memo3)
@nh2
nh2 / hackage-manual-haddocks-upload.py
Last active January 2, 2016 09:39
Uploads haddocks to Hackage.Use it when Hackage can't build your documentation (e.g. missing libraries).
#!/usr/bin/env python2
"""
Uploads haddocks to Hackage.
Use it when Hackage can't build your documentation (e.g. missing libraries).
Inspired by:
http://fuuzetsu.co.uk/blog/posts/2014-01-06-Fix-your-Hackage-documentation.html
"""
import getpass
@nh2
nh2 / Makefile
Last active January 3, 2016 19:29
Haskell: Benchmark safe foreign call overhead (inspired by https://groups.google.com/forum/#!topic/haskell-cafe/umeWETniZDM)
all:
ghc -O2 -fforce-recomp ffi-overhead.hs return.c && ./ffi-overhead
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 01fdec9..24584e0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -300,7 +300,8 @@ find_package(Qhull)
include("${PCL_SOURCE_DIR}/cmake/pcl_find_cuda.cmake")
# Find Qt5
-include(cmake/pcl_find_qt5.cmake)
+# nh2: Use Qt4 instead due to https://github.com/PointCloudLibrary/pcl/issues/477
@nh2
nh2 / realToFrac-rewrite-rules.txt
Created February 9, 2014 14:43
Discussion on #haskell about realToFrac performance
Does realToFrac compile to a no-op for (CFloat <-> Float / CDouble <-> Double)?
(14:27:30) kosmikus: nh2: it'll be a noop in many situations. CDouble normally is a newtype wrapper around Double. There are GHC Rule pragmas that'll turn realToFrac between Double and CDouble into a realToFrac between Double and Double by applying the constructor. Applying the constructor is a no-op, and there's a Double/Double instance having id as implementation.
(14:28:17) kosmikus: nh2: that being said, it's known that while simple applications of newtype constructors are newtypes, that doesn't translate to all contexts (such as mapping the constructor over a datastructure, for example)
(14:28:55) FreeFull: kosmikus: realToFrac isn't part of a typeclass though, it is defined as realToFrac = fromRational . toRational
(14:30:37) kosmikus: FreeFull: hm, you're right, I've been looking at the wrong place. let's check again.
(14:32:38) nh2: kosmikus, FreeFull: I really hope that realToFrac has rewrite rules for Double/CDouble and
@nh2
nh2 / matmult.hs
Created February 9, 2014 21:13
Example of how Haskell's forM_ [1..N] is slow and custom loops are fast (lack of fusion)
{-# LANGUAGE ScopedTypeVariables, BangPatterns #-}
-- Example of how forM_ [1..N] is slow
module Main (main) where
import Prelude hiding (read)
import Control.Monad
import Data.Vector ((!), Vector)
import qualified Data.Vector as V
@nh2
nh2 / time-natural.hs
Created March 1, 2014 01:33
Natural time in Haskell: `2 hours + 4 seconds`
{-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving #-}
newtype TimeUnit = TimeUnit Integer -- how many microseconds
deriving (Eq, Show, Num)
instance Num (TimeUnit -> TimeUnit) where
fromInteger n = \(TimeUnit scale) -> TimeUnit (n * scale)
-- a + b = ... -- task for you
@nh2
nh2 / generate-test-git.sh
Last active August 29, 2015 13:57
Generates a git repository with dual history and some branches on top (for fixing a Jenkins performance bug)
#!/bin/bash
# Creates a git repository called "testgit-generated"
# with two separate histories branching from the initial
# commit, each being 500 commits long.
# On top of each, we create 200 branches with one extra
# commit per branch.
# Should take around 30 seconds.
set -e
@nh2
nh2 / k-smallest-benchmark.hs
Created April 6, 2014 15:02
Benchmark for finding the k-smallest element in a list in Haskell
import Criterion.Main
import Data.List (sort)
import Data.Vector (Vector, fromList, unsafeThaw)
import qualified Data.Vector.Mutable as VM
import Data.Vector.Algorithms.Heap (select)
import Control.Monad.ST (runST)
import Data.Maybe (fromJust)
kSmallest1 :: Int -> [Int] -> Int
@nh2
nh2 / reverse-deps-sorted.hs
Created April 10, 2014 01:49
Sorts and prints Haskell packages by number of reverse dependencies
import Data.List (sort)
import qualified Data.Map as Map
import Distribution.PackDeps
import Control.Monad
main :: IO ()
main = do
newest <- loadNewest
let reverses = getReverses newest