Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE ViewPatterns, TemplateHaskell #-}
module HMQQ where
import Language.Haskell.TH.Quote
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
import Language.Haskell.Meta
import Data.Aeson
import Control.Monad
import qualified Data.HashMap.Strict as M
@aavogt
aavogt / concat.html
Created February 5, 2014 04:17
concatenate two svgs
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="4pt" height="3pt" viewBox="0 0 450 300" version="1.1">
<defs>
<g>
<symbol overflow="visible" id="glyph0-1">
<path style="stroke:none;" d="M 1.375 -10.9375 L 6.0625 -10.9375 C 7.445312 -10.9375 8.507812 -10.625 9.25 -10 C 10 -9.382812 10.375 -8.507812 10.375 -7.375 C 10.375 -6.21875 10 -5.332031 9.25 -4.71875 C 8.507812 -4.101562 7.445312 -3.796875 6.0625 -3.796875 L 4.203125 -3.796875 L 4.203125 0 L 1.375 0 Z M 4.203125 -8.890625 L 4.203125 -5.84375 L 5.75 -5.84375 C 6.300781 -5.84375 6.722656 -5.972656 7.015625 -6.234375 C 7.316406 -6.503906 7.46875 -6.882812 7.46875 -7.375 C 7.46875 -7.851562 7.316406 -8.222656 7.015625 -8.484375 C 6.722656 -8.753906 6.300781 -8.890625 5.75 -8.890625 Z "></path>
</symbol>
<symbol overflow="visible" id="glyph0-2">
<path style="stroke:none;" d="M 1.265625 -11.390625 L 3.875 -11.390625 L 3.875 0 L 1.265625 0 Z "></path>
</symbol>
<symbol overflow="visible" id="glyph0-3">
{-# LANGUAGE ConstraintKinds, RankNTypes, TypeFamilies, FlexibleInstances #-}
{- | Description: representing functions that can be differentiated
The 'AnyRF' wrapper holds functions that can be used
for the objective (`f`) or for constraints (`g`). Many functions
in the instances provided are partial: this seems to be unavoidable
because the input variables haven't been decided yet, so you should
not be allowed to use 'compare' on these. But for now just use the
standard Prelude classes, and unimplementable functions (which
would not produce an 'AnyRF') are calls to 'error'.
@aavogt
aavogt / main.hs
Created May 1, 2014 19:29
HOpenCV contours crash
{-# LANGUAGE DataKinds #-}
module Main where
import OpenCV.ArrayOps
import OpenCV.ColorConversion
import OpenCV.Contours ( withContourList, cvMoments, cvGetHuMoments, cvDrawContours, cvContourArea )
import OpenCV.Core.CVOp ( cv )
import OpenCV.Core.CxCore
import OpenCV.Core.ImageUtil
import OpenCV.HighCV
@aavogt
aavogt / main.hs
Created May 7, 2014 20:04
opencv createVideoWriter needs a more restrictive type?
{-# LANGUAGE DataKinds #-}
module Main where
import OpenCV.HighCV
import OpenCV.Core.Image
main = do
cap <- createFileCapture "in.avi"
Just img <- cap
w <- createVideoWriter "out.avi" ('M','J','P','G') 1 (width img, height img)
@aavogt
aavogt / Interleaved.hs
Created May 20, 2014 23:07
UU-options ported to lens from lenses
{-# LANGUAGE NoMonomorphismRestriction,
FlexibleInstances,
ScopedTypeVariables,
RankNTypes,
FlexibleContexts #-}
module Options.UU.Interleaved where
import Control.Lens hiding (set)
import Data.Functor.Identity
import Control.Applicative.Interleaved
@aavogt
aavogt / tgpF.R
Last active August 29, 2015 14:02
formula-based interface for tgp
un.model.matrix <- function(partial, frml, df) {
mf <- model.frame(terms.formula(frml), df)
fullDesign <- model.matrix(terms.formula(frml), df)
if (ncol(partial) != ncol(fullDesign))
stop('ncol(partial) != ncol(fullDesign)')
asgn <- attr(fullDesign, 'assign')
cs <- attr(fullDesign, 'contrasts')
j <- 0
{-# LANGUAGE TemplateHaskell #-}
module PartialTypeSigs where
import qualified Data.Map as M
import Data.IORef
import System.IO.Unsafe
import Data.Maybe
import Language.Haskell.TH
@aavogt
aavogt / MkF.hs
Last active August 29, 2015 14:05
quasiquote for defunctionalization
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TemplateHaskell #-}
module MkF (MkF(..), mkF, mkFInstances) where
import Control.Applicative
import Data.HList.CommonMain
import Language.Haskell.TH.Quote
import Language.Haskell.TH
import Language.Haskell.Meta.Syntax.Translate (toType,toExp)
import qualified Language.Haskell.Exts as E
@aavogt
aavogt / a.c
Last active August 29, 2015 14:05
ghc does not check foreign import types
double f (double x) {
return (x*2);
}