Skip to content

Instantly share code, notes, and snippets.

-- stack --resolver lts-10.0 script
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
import qualified Data.Aeson as Json
import Data.Aeson.Encode.Pretty (encodePretty)
import Data.ByteString (ByteString)
import Data.ByteString.Lazy (writeFile)
import Data.Colour.SRGB (sRGB24)
import qualified Data.CSV.Conduit as Csv
import qualified Data.CSV.Conduit.Conversion as Csv
@tfausak
tfausak / xml-lens.hs
Created December 12, 2017 04:00
XML lenses have stumped me.
-- stack --resolver nightly-2017-12-01 script
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Text.Lazy.IO as LazyText
import Text.XML
import Text.XML.Lens
main :: IO ()
main = do
let original = parseText_ def "<root> <old>1</old> <old>2</old> </root>"
@tfausak
tfausak / haddock.hs
Created December 8, 2017 23:17
Some examples of weird Haddock behavior.
import Prelude hiding (id, mod, (+))
import qualified Documentation.Haddock.Parser as Haddock
import qualified Documentation.Haddock.Types as Haddock
main :: IO ()
main = runTests
--
-- problems
# The GHC team announced the second release candidate for the 8.2.2 release of
# GHC: https://mail.haskell.org/pipermail/ghc-devs/2017-October/014994.html
#
# This is an example `stack.yaml` file that you can use to try out the release
# candidate. Save this file in your current directory and run `stack setup`.
# After that you should be able to use Stack as normal, including
# `stack exec ghci` and `stack build`.
#
# If for whatever reason you don't want to use Stack, you can download the
# official release tarballs at: https://downloads.haskell.org/~ghc/8.2.2-rc2/
-- This is a small benchmark meant to see how fast the http-client library can
-- make requests. In particular, it's meant to compare the network library and
-- the socket library. <https://github.com/snoyberg/http-client/pull/306>
import qualified Control.Concurrent.Async as Async
import qualified Control.Monad as Monad
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import qualified Data.Text.Lazy as LazyText
import qualified Data.Text.Lazy.Encoding as LazyText
#!/usr/bin/env node
'use strict';
// This is a little JavaScript utility meant to be used with Rattletrap to
// reduce the size of Rocket League replay files. See this issue for more:
// <https://github.com/tfausak/rattletrap/issues/49>. Example usage:
//
// $ stack exec rattletrap decode < original.replay > original.json
// $ node strip-replay.js < original.json > stripped.json
// $ stack exec rattletrap encode < stripped.json > stripped.replay
import qualified Data.Text
import qualified Data.Text.Encoding
import qualified Hasql.Batch
import qualified Hasql.Connection
import qualified Hasql.DecodeResult
import qualified Hasql.Statement
main :: IO ()
main = do
#!/usr/bin/env stack
-- stack --resolver lts-9.0 script
import Codec.Archive.Tar as Tar
import Codec.Compression.GZip as Gzip
import Data.Function
import Data.Map as Map
import Data.Maybe as Maybe
import Network.HTTP.Client
import Network.HTTP.Client.TLS
import System.FilePath
@tfausak
tfausak / socket-http.hs
Last active October 17, 2017 21:20
Performs an HTTP request with the Socket library. https://hackage.haskell.org/package/socket
#!/usr/bin/env stack
-- stack --resolver lts-9.0 script
import qualified Control.Exception as Exception
import qualified Data.ByteString as Bytes
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import qualified System.Socket as Socket
import qualified System.Socket.Family.Inet as Socket
import qualified System.Socket.Protocol.TCP as Socket
import qualified System.Socket.Type.Stream as Socket
# The GHC team announced the first release candidate for the 8.2.2 release of
# GHC over the weekend: https://mail.haskell.org/pipermail/ghc-devs/2017-October/014777.html
#
# This is an example `stack.yaml` file that you can use to try out the release
# candidate. Save this file in your current directory and run `stack setup`.
# After that you should be able to use Stack as normal, including
# `stack exec ghci` and `stack build`.
#
# If for whatever reason you don't want to use Stack, you can download the
# official release tarballs at: https://downloads.haskell.org/~ghc/8.2.2-rc1/