<commit_before>{-# LANGUAGE OverloadedStrings, ScopedTypeVariables  #-}

module Main where

import Data.Char (isPunctuation, isSpace)
import qualified Data.Map as M
import Control.Monad.IO.Class (liftIO)
import Control.Monad (forM_, liftM)
import Control.Applicative
import Control.Concurrent (MVar, newMVar)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Encoding as TE

import Snap.Core
import Snap.Http.Server.Config
import Snap.Http.Server 
import Snap.Util.FileServe

import qualified Snap.Internal.Http.Types as Snap
import Network.WebSockets.Snap

import Data.List (foldl')

import TwitterOAuth -- imports 2 Snap handlers
import GeoChat.WebsocketServer (wsApplication)


simpleConfig :: Config m a
simpleConfig = foldl' (\accum new -> new accum) emptyConfig base where
    base = [hostName, accessLog, errorLog, locale, port, ip, verbose]
    hostName = setHostname (bsFromString "localhost")
    accessLog = setAccessLog (ConfigFileLog "log/access.log")
    errorLog = setErrorLog (ConfigFileLog "log/error.log")
    locale = setLocale "US"
    port = setPort 9160
    ip = setBind (bsFromString "127.0.0.1")
    verbose = setVerbose True
    bsFromString = TE.encodeUtf8 . T.pack


main :: IO ()
main = do
    httpServe simpleConfig $ site -- run with snap
    -- WS.runServer "0.0.0.0" 9160 $ application state  -- run without snap


site :: Snap ()
site = ifTop (serveFile "../public/index.html") <|> 
    route [ ("login", loginWithTwitterHandler) ] <|>
    route [ ("twitter_access", twitterAccessTokenHandler) ] <|>
    route [ ("ws", runWSSnap) ] <|>
    route [ ("", (serveDirectory "../public")) ] 

runWSSnap :: Snap ()
runWSSnap = do 
    state <- liftIO $ newMVar M.empty
    runWebSocketsSnap $ wsApplication state



<commit_msg>Some Haskell golf<commit_after>{-# LANGUAGE OverloadedStrings, ScopedTypeVariables  #-}

module Main where

import Data.Char (isPunctuation, isSpace)
import qualified Data.Map as M
import Control.Monad.IO.Class (liftIO)
import Control.Monad (forM_, liftM)
import Control.Applicative
import Control.Concurrent (MVar, newMVar)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Encoding as TE

import Snap.Core
import Snap.Http.Server.Config
import Snap.Http.Server 
import Snap.Util.FileServe

import qualified Snap.Internal.Http.Types as Snap
import Network.WebSockets.Snap 

import Data.List (foldl')

import TwitterOAuth -- imports 2 Snap handlers
import GeoChat.WebsocketServer (wsApplication)


simpleConfig :: Config m a
simpleConfig = foldl' (\accum new -> new accum) emptyConfig base where
    base = [hostName, accessLog, errorLog, locale, port, ip, verbose]
    hostName = setHostname (bsFromString "localhost")
    accessLog = setAccessLog (ConfigFileLog "log/access.log")
    errorLog = setErrorLog (ConfigFileLog "log/error.log")
    locale = setLocale "US"
    port = setPort 9160
    ip = setBind (bsFromString "127.0.0.1")
    verbose = setVerbose True
    bsFromString = TE.encodeUtf8 . T.pack


main :: IO ()
main = do
    httpServe simpleConfig $ site -- run with snap
    -- WS.runServer "0.0.0.0" 9160 $ application state  -- run without snap


site :: Snap ()
site = ifTop (serveFile "../public/index.html") <|> 
    route [ ("login", loginWithTwitterHandler) ] <|>
    route [ ("twitter_access", twitterAccessTokenHandler) ] <|>
    route [ ("ws", liftIO (newMVar M.empty) >>= runWebSocketsSnap . wsApplication) ] <|>
    route [ ("", (serveDirectory "../public")) ] 

{'fraction_non_alphanumeric': 0.1124327386009629, 'fraction_numerical': 0.011328235627301049, 'mean_word_length': 3.960674157303371, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '167344', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1083, 'n_words': 329}