# time.gif

DevFeed: [time.gif](<https://devfeed.tech/articles/time-gif-30840.md>)

Original publisher: [Read original article](<https://hookrace.net/blog/time.gif/>)

Published: 2017-08-10T22:00:00Z

Content type: article

Language: en

Sources: [Dennis Felsing](<https://devfeed.tech/sources/dennis-felsing.md>)

Topics: [Haskell](<https://devfeed.tech/topics/haskell.md>), [Code](<https://devfeed.tech/topics/code.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [HTTP](<https://devfeed.tech/topics/http.md>), [IO](<https://devfeed.tech/topics/io.md>)

Tags: [2017](<https://devfeed.tech/tags/2017.md>), [browsers](<https://devfeed.tech/tags/browsers.md>), [cpu](<https://devfeed.tech/tags/cpu.md>), [encoding](<https://devfeed.tech/tags/encoding.md>), [gif](<https://devfeed.tech/tags/gif.md>), [haskell](<https://devfeed.tech/tags/haskell.md>), [http](<https://devfeed.tech/tags/http.md>), [programming](<https://devfeed.tech/tags/programming.md>), [server](<https://devfeed.tech/tags/server.md>)

## AI overview

time.gif is an endless GIF that displays the current UTC time. Written in Haskell, it generates each frame dynamically and streams the frames over an HTTP connection. The article notes Safari compatibility issues and describes optimizations for CPU use, connection capacity, and bandwidth.

## Source excerpt

This is an endless GIF that always shows the current time in UTC: Source Code (From reports it doesn't seem to work on Safari, other browsers should be fine.) time.gif is written in Haskell and works by dynamically generating each frame of the GIF and slowly feeding them over the HTTP connection. There is no guarantee that this GIF shows a reasonable time and this is just for fun anyway, so better don't build your next project based on the time from this GIF. If my server is overloaded, you can try compiling it yourself and run it locally. Update: Optimized, runs at less than 1% CPU with 500 simultaneous connections open, LZW encoding reduces bandwidth from 4 KB/s to 300 B/s. -- Wait for incoming connections and start delivering a GIF to them loop :: Int -> FrameSignal -> Socket -> IO () loop delay frameSignal sock = do (conn, _) <- accept sock forkIO $ body conn loop delay frameSignal sock where body c = do f <- receiveMSignal frameSignal sendAll c $ msg $ initialFrame (delay `div` 10000) f nextFrame c nextFrame c = do f <- receiveMSignal frameSignal sendAll c $ frame (delay `div` 10000) f nextFrame c msg content = B.intercalate "\r\n" [ "HTTP/1.0 200 OK" , "Server: gifstream/0.1" , "Content-Type: image/gif" , "Content-Transfer-Encoding: binary" , "Cache-Control: no-cache" , "Cache-Control: no-store" , "Cache-Control: no-transform" , "" , content ] This is cannibalized from gifstream, which lets you play snake and have people watch a GIF livestream. It was actually created as a Christmas exercise for students of the Programming Paradigms course at KIT. Discuss on Hacker News (2022-10-27) (previous thread from 2017-08-12)