Skip to content

Instantly share code, notes, and snippets.


Wander Hillen WJWH

View GitHub Profile
WJWH / Main.hs
Last active Apr 18, 2022
Files accompanying blog post on
View Main.hs
{-# LANGUAGE OverloadedStrings, DeriveGeneric, DerivingStrategies, DeriveAnyClass #-}
module Main where
import Prelude hiding (foldl)
import Conduit hiding (connect)
import Data.Attoparsec.ByteString as Attoparsec
import Data.Attoparsec.ByteString.Char8
import qualified Data.ByteString as B
import Data.Aeson
import Data.Conduit.Attoparsec
WJWH / gist:f3a196e65fdabd6eace5f89da430600e
Created Oct 1, 2021
Server that does no syscalls for handling connections
View gist:f3a196e65fdabd6eace5f89da430600e
// Extremely hacky server program that will send a standard response
// to every client that connects, then closes the connection. Will
// issue no system calls (as measured by `strace`) after initial setup
// no matter how many requests are served.
// Yes, this program is sorely lacking in error checking. It's a toy
// and not meant to be taken seriously.
// compile with gcc no_syscall_server.c -luring
View event_benchmark.hs
-- To benchmark, make sure to expose the GHC.Event.* in /libraries/base/base.cabal,
-- otherwise GHC will complain that they are hidden modules.
import GHC.Event.Manager hiding (closeFd)
import GHC.Event.Internal
import GHC.Event.IoUring as IoUring
import GHC.Event.EPoll as Epoll
import Control.Monad
import Data.Time
import System.Posix.IO
View gist:7867b0726fa6d667bb9c456c52bc303c
{-# LANGUAGE OverloadedStrings, BangPatterns, GeneralizedNewtypeDeriving, CPP #-}
module Main where
#include <sys/epoll.h>
import Foreign.C.Error (eNOENT, getErrno, throwErrno,
throwErrnoIfMinus1, throwErrnoIfMinus1_)
import Foreign.C.Types
import Foreign.Marshal hiding (void, newArray)
View gist:23e878474404be4b50ff3b02023a07a5
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Foreign.C.Types
import System.Posix.IO
import System.Posix.Types
import System.Linux.IO.URing
import System.Linux.IO.URing.PollEvent
View gist:7c88a2a066f117bf2280ae4b40dbc216
(gdb) x/80a 0x42009ffe28-80
0x42009ffdd8: 0x2d68 0x718018 <base_GHCziEventziPSQ_zdwunsafeInsertNew_info+2408>
0x42009ffde8: 0x42003216b1 0x8
0x42009ffdf8: 0x4200613ed9 0x7899c0 <ghczmbignum_GHCziNumziInteger_integerToWordzh_info+48>
0x42009ffe08: 0x769528 <base_GHCziEventziIoUring_zdwconstructUserdata_info+816> 0x0
0x42009ffe18: 0x1 0x825fd0 <stg_ret_p_info>
0x42009ffe28: 0x7ffff45e0940 0x75e7c8 <base_SystemziLinuxziIOziURingziRing_zdwpushSqe_info+264>
0x42009ffe38: 0x7ffff45dc040 0x7ffff45dc100
0x42009ffe48: 0x7ffff45e0940 0xa19
0x42009ffe58: 0x1ff 0xa19
View gist:6a33d8a607d3d55c7ada3a88ee35ec06
(gdb) bt
at includes/rts/storage/ClosureMacros.h:255
#1 0x0000000000a044e6 in evacuate (p=0x420193ce48) at rts/sm/Evac.c:591
#2 0x0000000000a14ddb in scavenge_small_bitmap (p=0x420193ce48, size=1,
bitmap=0) at rts/sm/Scav.c:289
#3 0x0000000000a17692 in scavenge_stack (p=0x420193ce48,
stack_end=0x420193cf80) at rts/sm/Scav.c:1923
#4 0x0000000000a16e15 in scavenge_one (p=0x420193cbf8) at rts/sm/Scav.c:1484
#5 0x0000000000a17218 in scavenge_mutable_list (bd=0x4201500880, gen=0xcb88e0)
View gist:97a102791e6ee08d98cc20145d9ba29a
{-# LANGUAGE OverloadedStrings #-}
-- Echo server program
module Main (main) where
import Control.Concurrent
import Control.Concurrent.MVar
import qualified Control.Exception as E
import Control.Monad (unless, forever, void)
import qualified Data.ByteString as S
import qualified Data.ByteString.Char8 as S8
WJWH / gist:2d4cb80f2799256e8703d2e904d0b707
Last active Aug 25, 2019
Generic dockerfile for statically compiled Crystal applications
View gist:2d4cb80f2799256e8703d2e904d0b707
# See for the reasoning behind each line
# Build stage
FROM durosoft/crystal-alpine:0.28.0 as build
COPY shard.yml shard.yml
RUN shards install --production
COPY . ./
RUN crystal build src/ --release --static
View gist:8c2b4fe31e29c77e4a165bd50a71a6a9
# omg this is such a long comment, good thing I can spread it out over multiple lines like this so it will be clear for my colleagues what this code will do