Skip to content

Instantly share code, notes, and snippets.

We couldn’t find that file to show.
We couldn’t find that file to show.
import Network.Socket
import Control.Concurrent
import qualified System.IO as IO
type HandlerFunc = SockAddr -> String -> IO ()
serveLog :: String -- ^ Port number or name; 514 is default
-> HandlerFunc -- ^ Function to handle incoming messages
-> IO ()
serveLog port handlerfunc = withSocketsDo $
@paul-r-ml
paul-r-ml / haskellTcpProxy.hs
Created December 12, 2010 13:06
simple Haskell TCP proxy
module Main where
import Control.Concurrent (forkIO)
import Control.Monad (forever, unless)
import Network (PortID(PortNumber),listenOn)
import Network.Socket hiding (listen,recv,send)
import Network.Socket.ByteString (recv,sendAll)
import qualified Data.ByteString as S
import System.Posix (Handler(Ignore),installHandler,sigPIPE)
@paul-r-ml
paul-r-ml / ree memory leaks
Created December 18, 2010 23:32
REE leaks memory when handling big strings. Run this script with ruby ree and string_size >= 7 to see it.
### usage : ruby(version) mem.rb STRING_SIZE [cow]
### 1 < string_size < 9
### cow to activate copy on write (ree only)
def ram_usage
`pmap #{Process.pid} | tail -1`.split[1][0..-2].to_i
end
@paul-r-ml
paul-r-ml / gist:982599
Created May 20, 2011 09:07
hakyll groups
group "processTags" $ match "published/*" $ compile $ readPageCompiler
create "tags" $
( requireAll
( (inGroup $ Just "processTags") `mappend` "published/*" )
(\_ ps -> readTags ps :: Tags String) )
-- Add a tag list compiler for every tag
match "tags/*" $ route $ setExtension ".html"
metaCompile $ require_ "tags"
@paul-r-ml
paul-r-ml / gist:998640
Created May 30, 2011 09:16
Hakyll, list posts grouped by year
---- group posts by years
groupByYear :: [Page a] -> [(String, [Page a])]
groupByYear = map (\pg -> ( year (head pg), pg) ) .
groupBy (\ a b -> year a == year b)
where year :: Page a -> String
year = take 4 . takeBaseName . getField "path"
addYearList :: String
@paul-r-ml
paul-r-ml / gist:1363557
Created November 14, 2011 08:54
simple chat server example
module Main where
import Data.Char (ord)
import Network.Socket hiding (recv)
import qualified Data.ByteString as S
import qualified Data.ByteString.Char8 as C8
import qualified Data.ByteString.UTF8 as U8
import Network.Socket.ByteString (recv, sendAll)
@paul-r-ml
paul-r-ml / gist:1390899
Created November 24, 2011 08:32
string sh-like interpolation based on audrey tang previous work
{-# LANGUAGE TemplateHaskell, TypeSynonymInstances, FlexibleInstances #-}
module Text.InterpolatedString.Interp (qc, q) where
import qualified Language.Haskell.TH as TH
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C8
import Language.Haskell.TH.Quote
data StringPart = Literal String | Binding String deriving Show