Skip to content

Instantly share code, notes, and snippets.

@thsutton
thsutton / README.md
Created February 3, 2015 03:06
Running a testing slapd instance

Running a test slapd instance

I use this to run a slapd instance for testing schemata, searched, etc. during development.

Usage

mkdir -p schema
@thsutton
thsutton / secret.sh
Last active August 29, 2015 14:08
Edit a GPG encrypted file, maintaining (and extending) multiple recipients
#!/bin/sh
#
# Access a shared secret file.
set -eu
error() {
echo $1
exit 1
}
@thsutton
thsutton / demo.hs
Last active August 29, 2015 14:07 — forked from anonymous/demo.hs
module Main where
import Control.Applicative
import Data.Char
import Data.List
import Options.Applicative
import Options.Applicative.Types
-- * Options parsers
@thsutton
thsutton / demo.hs
Last active August 29, 2015 14:07 — forked from anonymous/demo.hs
module Main where
import Control.Applicative
import Data.Char
import Data.List
import Options.Applicative
import Options.Applicative.Types
-- * Options parsers
@thsutton
thsutton / main.hs
Created August 8, 2014 05:52
Monad logger
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Applicative
import Control.Monad.Except
import Control.Monad.IO.Class ()
import Control.Monad.Reader
@thsutton
thsutton / example.hs
Created August 8, 2014 00:00
Monad transformers example - a monad with exceptions, logging, and configuration.
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Main where
import Control.Applicative
import Control.Monad.Except
import Control.Monad.IO.Class ()
import Control.Monad.Reader
import Control.Monad.Writer
@thsutton
thsutton / stream-randoms.lhs
Created July 24, 2014 01:03
Generate a stream of random numbers.
This is a Literate Haskell file: lines begining with `>` are Haskell
code and other lines are just plain old text (Markdown, actually). If
you save this file with a `.lhs` extension, the Haskell tools will all
run it just like a normal `.hs` file.
We're going to generate lists of random numbers and will need a few
helpful functions from the standard library:
> import Data.List (unfoldr)
> import System.Random
@thsutton
thsutton / make-drupal-file-field-private.sh
Last active February 9, 2022 07:52
Hold your hand through the process of converting an existing Drupal 7 file field to use the private file system. Update the $FIELD variable (and, if required, the path and arguments for drush) and do what it tells you to.
#!/bin/sh
#
# This script will hold your hand during the process of converting an existing Drupal 7 file field from public to private.
#
# http://twitter.com/thsutton
# http://www.linkedin.com/pub/thomas-sutton/55/391/350
# http://thomas-sutton.id.au/
set -eu
@thsutton
thsutton / fix-packt-epubs.sh
Created September 23, 2013 11:28
Shell script to fix the "unique" identifiers in EPUB files sold by Packt Publishing.
#!/bin/sh
#
# fixpacktepubs.sh
#
# Process the EPUB files in the current directory and recreate them with the
# ISBN as the unique value. This script was written because Packt Publishing
# sell EPUBs with non-unique unique identifiers and it assumes that the EPUBs
# being process are structured like Packt's.
#
@thsutton
thsutton / splitInto.hs
Created July 13, 2013 14:58
splitInto :: Int -> [a] -> [[a]]
splitInto :: Int -> [a] -> [[a]]
splitInto n l
| n <= 0 = error "splitInto: n < 1"
splitInto n [] = []
splitInto n l = case splitAt n l of
(c, []) -> [c]
(c, r ) -> c:(splitInto n r)