Skip to content

Instantly share code, notes, and snippets.

View danieldk's full-sized avatar

Daniël de Kok danieldk

View GitHub Profile
scoreFromLine = fromJust . readDouble . (!! 3) . L.split (c2w '#')
@danieldk
danieldk / gist:805950
Created February 1, 2011 14:51
Handy Python settings for the reading group
;; Three handy settings for the Python mode:
;;
;; - Set indentation to two spaces.
;; - Interpret as Python 3 code.
;; - Autoindent when pressing return.
;;
(add-hook 'python-mode-hook
(lambda ()
(setq python-indent 2
python-default-version 3)
@danieldk
danieldk / gist:849066
Created March 1, 2011 12:40
Fold for rose tree zippers
tzFold :: (a -> TreePos Full b -> a) -> a -> TreePos Full b -> a
tzFold f acc t =
foldSiblings $ foldChildren $ f acc t
where
foldChildren acc' =
case firstChild t of
Just c -> tzFold f acc' c
Nothing -> acc'
foldSiblings acc' =
case next t of
@danieldk
danieldk / gist:924270
Created April 17, 2011 17:44
FeatureValue
import Data.Char (isNumber, isUpper)
import Data.List (genericLength, genericTake)
import Text.Printf (printf)
data FeatureValue =
FeatureValue {
feature :: String,
value :: Double
} deriving (Show)
@danieldk
danieldk / gist:924272
Created April 17, 2011 17:45
Prefixes and suffixes
prefix :: Integer -> String -> [FeatureValue]
prefix n =
map (flip FeatureValue 1 . printf "prefix(%s)") . prefixes n
suffix :: Integer -> String -> [FeatureValue]
suffix n =
map (flip FeatureValue 1 . printf "suffix(%s)") . prefixes n . reverse
prefixes :: Integer -> String -> [String]
prefixes n word = do
@danieldk
danieldk / gist:924275
Created April 17, 2011 17:46
Word capitalization
capitalization :: String -> [FeatureValue]
capitalization (x:_)
| isUpper x = [FeatureValue "capitalized" 1]
| otherwise = [FeatureValue "capitalized" 0]
@danieldk
danieldk / gist:924320
Created April 17, 2011 18:25
Feature extraction
feature :: [String -> [FeatureValue]] -> [FeatureValue]
features templates word = do
template <- templates
feature <- template word
return feature
@danieldk
danieldk / gist:924336
Created April 17, 2011 18:39
Capitals and numbers
nCapitals :: String -> [FeatureValue]
nCapitals =
return . FeatureValue "capitals" . genericLength . filter isUpper
nNumbers :: String -> [FeatureValue]
nNumbers =
return . FeatureValue "numbers" . genericLength . filter isNumber
@danieldk
danieldk / gist:1136473
Created August 10, 2011 09:48
An intersperse enumeratee
import Control.Monad.Trans.Class (lift)
import Data.Enumerator (Enumeratee, Step(..), Stream(..), runIteratee)
import qualified Data.Enumerator.List as EL
intersperse :: (Monad m) => a -> Enumeratee a a m b
intersperse v = first
where
first (Continue k) = do
h <- EL.head
case h of
@danieldk
danieldk / gist:1280960
Created October 12, 2011 11:22
Build DBXML against Berkeley DB 5.1
--- dbxml-2.5.16/dbxml/configure.orig 2011-10-12 13:14:17.000000000 +0200
+++ dbxml-2.5.16/dbxml/configure 2011-10-12 13:18:28.000000000 +0200
@@ -2656,10 +2656,10 @@
DB_UTIL_PATH="<replace_with:_path_to_db_build>/build_unix"
# Check for a DB install tree
-if test `ls "$with_berkeleydb"/lib/libdb-*.la 2>/dev/null | wc -l` -gt 0 ; then
+if test `ls "$with_berkeleydb"/lib/libdb-5.3*.a 2>/dev/null | wc -l` -gt 0 ; then
{ echo "$as_me:$LINENO: checking for Berkeley DB version from install tree" >&5
echo $ECHO_N "checking for Berkeley DB version from install tree... $ECHO_C" >&6; }