Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / test.hs
Created May 26, 2015 01:29
Invoke GHC to check that files compile in a cabal test suite
module Main where
import System.Exit
import System.Process
main :: IO ()
main = do
(c1, o1, e1) <- readProcessWithExitCode "ghc" ["-ilib", "-o", "/tmp/failure", "test/fail.hs"] ""
(c2, o2, e2) <- readProcessWithExitCode "ghc" ["-ilib", "-o", "/tmp/passure", "test/pass.hs"] ""
@thsutton
thsutton / Fails.hs
Created July 7, 2015 01:26
HLint can't parse type application in a list
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Foo where
import GHC.TypeLits
data Header (sym :: Symbol) (val :: Symbol)
type Foo = '[Header "X-Forwarded-For" "Satan"]
/** @file
*
* This code implements wraps and exports the OpenSSL hashing functions to Lua.
*
* To use this code arrange for it to be loaded by your Lua interpreter either
* by compiling it in or loading a shared library. You'll need to pass various
* flags to your compiler to get it to use the OpenSSL libraries, etc. I used
* something like this:
*
* gcc `pkg-config openssl --cflags --libs` -c lhash.c

A simple PHP wrapper for MAMP

MAMP is a pretty crappy environment, but it beats the shit out of building a decent environment myself and is marginally more convenient than working on a Linux VM. This little script makes it more useful (for me) by providing a fake php command in the $MAMP/Library/bin directory which calls the real php from the version you've configured MAMP to use.

Just put the accompanying script in the $MAMP/Library/bin directory and make it executable, then make sure that $MAMP/Library/bin is in your $PATH before /usr/bin (and any other directory containing an executable called php).

Then any invocation of php will be executed with the correct version (as far as MAMP cares, anyway!)

Future improvements include using the "next" php in $PATH if MAMP is not running.