Posts
3388
Following
203
Followers
339
Linux kernel maintainer. Compilers and virtualization at Parity Technologies.

@aks I’ve actually quite excited on getting back to vim from neovim but have done also some experiments like this Haskell one from 2010-11. Let’s just say that I did not pursue a career as a Haskell programmer after this ;-)

Looking back 2D maze is actually pretty good test probe for any language. It has a algorithm, I/O and graphics so it gives me fairly good evaluation how much I like or dislike a language :-)

module Maze where

import Control.Monad
import Foreign
import qualified Graphics.UI.SDL as SDL
import System.Random
import Data.List
import Data.Array

data Cell = Cell {
    top :: Bool,
    left :: Bool,
    visited :: Bool
} deriving (Show, Eq)

type Maze = Array (Int, Int) Cell

newCell = Cell {top = True, left = True, visited = False}

newMaze :: Int -> Int -> Maze
newMaze rows columns = listArray ((0, 0), (rows - 1, columns - 1)) (repeat newCell)

genMaze maze (r, c) (seed:seeds)
    | visited (maze ! (r, c)) == True = maze
    | otherwise = foldl traverse maze' ((permutations neighbours) !! index)
    where maze' = maze//[((r, c), (maze ! (r, c)) { visited = True })]
          locs = [(r - 1, c), (r + 1, c), (r, c - 1), (r, c + 1)]
          ((_, _), (rmax, cmax)) = (bounds maze)
          neighbours = [(r', c') | (r', c') <- locs,
                        r' >= 0 && r' <= rmax, c' >= 0 &&  c' <= cmax]
          index = seed `mod` (length neighbours)
          moveTo maze (r, c) (r', c')
              | visited cell'  = maze
              | r' < r = maze//[((r, c), cell { top = False })]
              | r' > r = maze//[((r', c'), cell' { top = False })]
              | c' < c = maze//[((r, c), cell { left = False })]
              | c' > c = maze//[((r', c'), cell' { left = False })]
              | otherwise = error "Invalid move"
              where cell = maze ! (r, c)
                    cell' = maze ! (r', c')
          traverse maze' (r', c') = genMaze (moveTo maze' (r, c) (r', c')) (r', c') seeds

hline :: Int -> Int -> Int -> SDL.Pixel -> SDL.Surface -> IO ()
hline x y width (SDL.Pixel pixel) screen = do
    screenWidth <- return (SDL.surfaceGetWidth screen)
    pixels <- castPtr `liftM` SDL.surfaceGetPixels screen
    forM_ [0..(width - 1)] $ \dx -> do
        pokeElemOff pixels (y * screenWidth + x + dx) pixel

vline :: Int -> Int -> Int -> SDL.Pixel -> SDL.Surface -> IO ()
vline x y height (SDL.Pixel pixel) screen = do
    screenWidth <- return (SDL.surfaceGetWidth screen)
    pixels <- castPtr `liftM` SDL.surfaceGetPixels screen
    forM_ [0..(height - 1)] $ \dy -> do
        pokeElemOff pixels ((y + dy) * screenWidth + x) pixel

main :: IO()
main = do
    startRow <- randomRIO (0 :: Int, rows - 1)
    startColumn <- randomRIO (0 :: Int, columns - 1)
    seeds <- replicateM (rows * columns) (randomRIO (0 :: Int, (max rows columns)))

    maze <- return (genMaze (newMaze rows columns) (startRow, startColumn) seeds)
    SDL.init [SDL.InitEverything]
    screen <- SDL.setVideoMode screenWidth screenHeight 32 []

    hline 0 0 screenWidth whitePixel screen
    hline 0 (screenHeight - 1) screenWidth whitePixel screen
    vline 0 0 screenHeight whitePixel screen
    vline (screenWidth - 1) 0 screenHeight whitePixel screen

    forM (assocs maze) $ \((r, c), cell) ->
        if (top cell) then do
            hline (blockWidth * c) (blockHeight * r) blockWidth whitePixel screen
        else do return ()

    forM (assocs maze) $ \((r, c), cell) ->
        if (left cell) then do
            vline (blockWidth * c) (blockHeight * r) blockHeight whitePixel screen
        else do return ()

    SDL.flip screen
    eventLoop
    SDL.quit

    where
        eventLoop = SDL.waitEvent >>= checkEvent
        checkEvent SDL.Quit = return()
        checkEvent (SDL.KeyUp _) = return()
        checkEvent _ = eventLoop

        blockWidth = 32
        blockHeight = 32
        rows = 16
        columns = 16
        screenWidth = columns * blockWidth
        screenHeight = rows * blockHeight
        whitePixel = SDL.Pixel 0x00FFFFFF
0
0
1

Jarkko Sakkinen

Edited 4 months ago
@aks It is actually a problem with many new comers to software industry. Always looking for better tools, and not enough focus on solving the *actual* problem, no matter what the tools or languages are :-)

Like CoPilot writing your Rust syntax shenanigans for you because it is too terrible mess for a humanbeing to write it by hand, is IMHO a "cult classic" of moden software development.
1
0
1
@aks Stuff that Ueber has done with Zig is amazing tho. This is not the same that I would disagree with the "Rust-decision", just saying that it is now industry-proven tool. I consider Ueber as "industry-proven" in this context.
1
0
1
@aks Because we have to deal with Rust in any case I'm just trying to make best of it I guess 🤷 So it is like "C++ thing" for me I guess. It is sort of like best practices modern C++ enforced by the compiler with a new syntax, isn't it?
1
0
1
@aks No and I hate learning new languages tbh :-) Latest I've learned before Rust was Python in 2005. Rust is sort of more "have to deal with" than whether it is in my own preferences,
1
0
1
For better or worse very C-programmer alike Rust code :-) You can still read it without knowing anything about Rust.
0
0
0

Jarkko Sakkinen

Edited 4 months ago
Now that I leaned to use Goblin with Mach-O binaries, and how I find my way to symbol address through those ways, I think as next step I'll write a my-purposes-only disassembler using Goblin and Capstone's #Rust bindings.

I have sort of this fuzzy big picture in my head what I might want to do with that and perhaps with using Aya EBPF sheanigans but have to do bunch or trials and errors first

Sort of interesting territory experiment anyhow despite successes and failures. Generally I'm more interested on Rust when it comes to kernel what can be done in QA side from user space than kernel code per se.

🤷
1
1
0
@miiko ofc and always
0
0
1

Jarkko Sakkinen

Tampere Sunday sightseeing
0
0
4

Jarkko Sakkinen

some funkier stuff produced some years ago https://analrecords.bandcamp.com/track/scum-cums #psytrance #suomisaundi
0
0
1

Jarkko Sakkinen

What I think of Biden/Trump? Pretty much the same feeling that I had when I did this track with my Slovakian-Finnish friend Vlado in 2020: https://globalfishmafia.bandcamp.com/track/i-dont-feel-anything

I was in Portland OR when 2016 elections happened, which was pretty cool I think or once in a lifetime historical experience, mind the result. Or actually, it is not my concern what I might mind the result. I only focus taking stand in the votes where I have a legit standing point in the first place.

E.g. I have a voting ticket for Finnish parliament, EU and LF deciding bodies. So I focus on those and deal with sometimes unfortunate reality.

#politics
0
1
0
Also learned that the compilation process is torture in this project. Putting all eggs for making that easier would be the first priority in my books
0
0
0

Jarkko Sakkinen

songs that stick in your brains forever once you hear them for the first time https://www.youtube.com/watch?v=NlgmH5q9uNk
1
1
1

Jarkko Sakkinen

Binary parsing with #Rust and #goblin https://jarkko.codeberg.page/2024/07/13/binary-parsing-with-goblin.html

The next step is to use #Capstone bindings to disassemble the victim symbol.

#rustlang
0
1
0
I use Firefox for watching garbage (because of Widevine DRM), and GNOME Web for work stuff.
1
0
0

Jarkko Sakkinen

For people concerned about #Mozilla #Firefox: #GNOME Web supports Firefox Sync out of the box.
2
0
2
@alerque right i counted blink as webkit derivative
1
0
0
@ringtailringo I blindly ignore this nonsense, sorry.
1
0
0
Show older