Skip to content

Instantly share code, notes, and snippets.

@NathanHowell
NathanHowell / ReaderT
Created July 20, 2014 07:39 — forked from jg/ReaderT
connectionUrl :: Monad m => ReaderT m Config B.ByteString
-- withConnection
-- :: (Database.PostgreSQL.Simple.Internal.Connection -> IO c)
-- -> ReaderT Config IO c
withConnection f = do
url <- connectionUrl
liftIO $ bracket (connectPostgreSQL url) close f
@NathanHowell
NathanHowell / centos7-upgrade.sh
Created July 26, 2014 22:44
Upgrade CentOS 6.5 to 7.0.1406 using the prerelease upgrade tools
#!/bin/bash
set -e
cat > /etc/yum.repos.d/upgrade.repo <<END
[upgrade]
name=upgrade
baseurl=http://dev.centos.org/centos/6/upg/x86_64/
enabled=1
gpgcheck=0
END
{-# LANGUAGE RankNTypes #-}
import qualified GHC.Event
data TimerManager2 = TimerManager2
{ registerTimeout :: Int -> GHC.Event.TimeoutCallback -> IO GHC.Event.TimeoutKey
, updateTimeout :: GHC.Event.TimeoutKey -> Int -> IO ()
, unregisterTimeout :: GHC.Event.TimeoutKey -> IO ()
}
@NathanHowell
NathanHowell / generic-fold.hs
Last active August 29, 2015 14:06
Foldable for GHC.Generic instances
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
import GHC.Generics
import Data.Foldable as Foldable
import Data.Monoid
foo :: Int -> Int
foo x | x > 0 = x -1
foo x | otherwise = 0
@NathanHowell
NathanHowell / JsonSchemaRDD.scala
Created November 15, 2014 00:37
SchemaRDD to row JSON conversion
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@NathanHowell
NathanHowell / please-no.hs
Created June 23, 2015 07:36
Really terrible HTTP CONNECT proxy for Haskell/WAI
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
import Control.Concurrent (forkIO, newEmptyMVar, putMVar, takeMVar)
import Control.Exception (finally)
import Control.Monad
import Control.Monad.Trans (liftIO)
import Data.ByteString.Char8 ()
import qualified Data.ByteString as B
import Data.Monoid
using System;
using System.IO;
using System.Linq;
namespace WordCountCS
{
class Program
{
static void Main(string[] args)
{
@NathanHowell
NathanHowell / rover.hs
Created November 13, 2010 06:29 — forked from arocks/rover.hs
import Control.Monad (liftM)
import Data.Complex (Complex(..))
import Data.List (foldl, lookup, words)
import Text.Printf (printf)
data Direction = N | E | S | W deriving (Show,Read,Eq)
data Instruction = R | L | M deriving (Show,Read)
data Vector = Vector (Complex Double) (Complex Double)
-- map directions to Complex numbers
withArgsM :: Monad m
=> Expression
-> (forall a . StructFields a => a -> m s)
-> m s
withArgsM exp f = inner vars f where
vars = nub [ x :: Factor | x <- universeBi exp ]
inner :: Monad m => [Factor] -> (forall a . StructFields a => a -> m s) -> m s
inner (x:xs) f = inner xs (\ x -> f ((undefined::Double) & x))
inner [] f = f ()