Skip to content

Instantly share code, notes, and snippets.

Avatar

Wander Hillen WJWH

View GitHub Profile
@WJWH
WJWH / day15.hs
Created December 15, 2022 17:11
Haskell solution progression for AOC 2022 day 15 part 2
View day15.hs
module Main where
import Utils
import Control.Concurrent
import Control.Concurrent.Chan
import Data.List
import qualified Data.Map.Strict as M
import qualified Data.Set as S
import Data.Range as Range
@WJWH
WJWH / Main.hs
Last active April 18, 2022 19:30
Files accompanying blog post on wjwh.eu
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
WJWH / gist:f3a196e65fdabd6eace5f89da430600e
Created October 1, 2021 14:16
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
@WJWH
WJWH / gist:7867b0726fa6d667bb9c456c52bc303c
Created July 20, 2020 18:56
Not segfaulting program
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
#0 LOOKS_LIKE_CLOSURE_PTR (p=0x318)
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
WJWH / gist:2d4cb80f2799256e8703d2e904d0b707
Last active August 25, 2019 08:24
Generic dockerfile for statically compiled Crystal applications
View gist:2d4cb80f2799256e8703d2e904d0b707
# See https://wjwh.eu/posts/2019-07-21-static-crystal-images.html 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/my_app.cr --release --static