Skip to content

Instantly share code, notes, and snippets.

View WordCount.cs
using System;
using System.IO;
using System.Linq;
namespace WordCountCS
{
class Program
{
static void Main(string[] args)
{
View 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
View gist:1071154
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 ()
@NathanHowell
NathanHowell / gist:1096039
Created Jul 20, 2011
Length prefixed gzipped streams
View gist:1096039
import Data.Binary.Get
import qualified Data.ByteString as B
import qualified Data.Enumerator as E
import qualified Data.Enumerator.Binary as EB
import qualified Codec.Zlib.Enum as Z
unzipStream :: E.Iteratee B.ByteString IO b
-> E.Iteratee B.ByteString IO b
unzipStream sink = do
-- read four bytes off the wire into a bytestring
View gist:1466063
{-# OPTIONS_GHC -fno-warn-deprecations #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
module Main (main) where
import Control.Monad (when)
import qualified Data.ByteString.Lazy as BL
@NathanHowell
NathanHowell / ParseInt64.c
Created Jan 24, 2012
Benchmarking and QuickChecking readInt.
View ParseInt64.c
#line 1 "ParseInt64.rl"
#include <HsFFI.h>
#line 7 "ParseInt64.c"
static const int ParseInt64_start = 1;
static const int ParseInt64_first_final = 3;
static const int ParseInt64_error = 0;
@NathanHowell
NathanHowell / ghc20442_0.s
Created Feb 13, 2012
.loc out of order on line 65
View ghc20442_0.s
This file has been truncated, but you can view the full file.
.file "/tmp/ghc20442_0/ghc20442_0.bc"
.file 1 "/home/nhowell/source/ghc-profiling/libraries/unix/dist-install/build/System/Posix/User.hs"
.section .debug_info,"",@progbits
.Lsection_info:
.section .debug_abbrev,"",@progbits
.Lsection_abbrev:
.section .debug_aranges,"",@progbits
.section .debug_macinfo,"",@progbits
View gist:1858260
import Data.Aeson
import Data.Attoparsec
import qualified Data.Enumerator as E
import qualified Data.Enumerator.Binary as Eb
import qualified Data.Enumerator.List as El
import qualified Data.ByteString as BS
byteLines :: Monad m => E.Enumeratee BS.ByteString BS.ByteString m b
byteLines = Eb.splitWhen (== 10) -- 10 is LF
View gist:2633184
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Forall where
import Control.Applicative
import Data.Aeson
import Control.Monad
data Bar = Bar Int
data Baz = Baz Int Int
View bar.c
int someCall(int x)
{
return x * x;
}
You can’t perform that action at this time.