Skip to content

Instantly share code, notes, and snippets.

View mstksg's full-sized avatar

Justin Le mstksg

View GitHub Profile
@mstksg
mstksg / dead-code-tests.hs
Created November 13, 2013 21:21 — forked from anonymous/dead-code-tests.hs
Three files, one with only main, one with main + non-referenced IO object, one with main + referenced IO object (technically, one with a larger main IO object). The non-referenced IO object is never compiled, as the resulting object files have the same md5sum.
-- test1.hs
-- No dead code: compiles to 1.22M executable
-- with stripped .o 1320 byes
-- .o file md5sum: 35ccd1647c772a5757fba3ae8bfa6542
main :: IO ()
main = getLine >>= print
-- test2.hs
-- With dead code: compiles to 1.22M executable
@mstksg
mstksg / shakeup.sh
Created September 17, 2013 00:53
Generate a Shakefile scaffold
#!/bin/bash
SHAKEFILE=${1:-"Shakefile"}
if [ ! -e "$SHAKEFILE" ]; then
tee -a "$SHAKEFILE" << 'EOF' > /dev/null
import Development.Shake
opts = shakeOptions { shakeFiles = ".shake/"
@mstksg
mstksg / assertion dsl
Last active December 22, 2015 20:19
Assertion DSL for complex conditional
import Data.Maybe (isJust)
assert :: Bool -> Maybe ()
assert True = Just ()
assert False = Nothing
checkAssertions :: Maybe () -> Bool
checkAssertions = isJust
checkMatch :: Person -> Person -> Bool
@mstksg
mstksg / Postgresql Runtime Error
Last active December 20, 2015 19:19
Runtime error on selectDistinct on many-to-many join with sorting. No error if ran with sqlite bindings. Also, select (not distinct) works fine.
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE OverloadedStrings #-}
import System.Random
import Control.Monad.Random
import Control.Monad
metroStep :: (RandomGen g) => (Double -> Double) -> Double -> Double -> Rand g Double
metroStep p step x = do
dx <- getRandomR (-step, step)
let
newx = x + dx
p0 = p x