Skip to content

Instantly share code, notes, and snippets.

View tibbe's full-sized avatar

Johan Tibell tibbe

View GitHub Profile
15:26:05 [I] Bootstrapping "project" in "/tmp/event"
15:26:05 [I] /tmp/event $ /usr/local/git/bin/git clone -n http://github.com/tibbe/event.git /tmp/event/.gittmp
15:26:05 [D] Executing /usr/local/git/bin/git clone -n http://github.com/tibbe/event.git /tmp/event/.gittmp ('/tmp/event')
15:26:05 [W] [Status 128]
15:26:05 [C] Checkout of project failed!
Failure applying upstream changes: /tmp/event $ /usr/local/git/bin/git clone -n http://github.com/tibbe/event.git /tmp/event/.gittmp failed
type TimeoutCallback = IO ()
data EventManager = EventManager
{ emTimeouts :: IORef (PSQ TimeoutCallback)
, ...
}
type TimeoutCallback = IO ()
data EventManager = EventManager
{ emTimeouts :: IORef (PSQ TimeoutCallback)
, ...
}
-- | Register a timeout in the given number of milliseconds.
registerTimeout :: EventManager -> Int -> TimeoutCallback -> IO TimeoutKey
registerTimeout mgr ms cb = do
key <- newUnique (emUniqueSource mgr)
now <- getCurrentTime
let expTime = fromIntegral ms / 1000.0 + now
_ <- atomicModifyIORef (emTimeouts mgr) $ \q ->
let q' = Q.insert key expTime cb q in (q', q')
wakeManager mgr
return $! TK key
type TimeoutQueue = Q.PSQ TimeoutCallback
type TimeoutEdit = TimeoutQueue -> TimeoutQueue
applyTimeoutEdits :: TimeoutQueue -> [TimeoutEdit] -> TimeoutQueue
applyTimeoutEdits = foldr ($!)
{-# LANGUAGE OverloadedStrings #-}
module Main where
import qualified Data.ByteString.Lazy as S
import qualified Data.Text as T
import qualified Data.Text.Lazy.Encoding as E
import Data.Text.Template
member :: Int -> [Int] -> Bool
member _ [] = False
member n (x:xs)
| x == n = True
| otherwise = member n xs
member :: Int -> [Int] -> Bool
member n = go
where
go [] = False
go (x:xs)
| x == n = True
| otherwise = go xs
filter :: (a -> Bool) -> [a] -> [a]
filter _ [] = []
filter p (x:xs)
| p x = x : filter p xs
| otherwise = filter p xs
filter :: (a -> Bool) -> [a] -> [a]
filter p = go
where
go [] = []
go (x:xs)
| p x = x : go xs
| otherwise = go xs