Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
module Main where
import qualified Data.DateTime as DATE
import qualified Control.Monad as C
import qualified Control.Monad.Trans as CT
import qualified Database.Redis as R
import qualified System.Random as SR
import qualified Data.ByteString.UTF8 as U
-- a nice find from the web - picking an elt at random
pick :: [a] -> IO a
pick xs = SR.randomRIO (0, (length xs - 1)) >>= return . (xs !!)
main = do
now <- C.liftM DATE.toSeconds $ DATE.getCurrentTime
words <- (C.liftM lines . readFile) "/etc/dictionaries-common/words"
-- make a list of tuples of (utc_second,random-word)
-- pairs a random word to each second of previous 24 hour period
rw <- mapM (\i -> pick words >>= \rw -> return (i,rw)) [(now - 86400)]
conn <- R.connect R.defaultConnectInfo
R.runRedis conn $ do
-- empty redis
fr <- R.flushall
CT.liftIO $ putStrLn $ show fr
-- set time -> word
mapM_ (\j -> R.set (U.fromString $ show $ fst j) (U.fromString $ snd j)) rw
return ()
return ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment