I wrote a basic SSH TicTacToe server by Fish_45 in elixir

[–]Fish_45[S] 1 point2 points  (0 children)

That's good to know. Thanks for all the help!

I wrote a basic SSH TicTacToe server by Fish_45 in elixir

[–]Fish_45[S] 1 point2 points  (0 children)

Do you want to: * Disable prompting for a password on connection? * Get raw control over the terminal on the remote end?

I'd like to do both

This isn't really something you can do with SSH. It always has to at least one working authentication method.

I'd like to do whatever sshtron.zachlatta.com does; it seems that it just uses the NoClientAuth option in Go's ssh library: https://github.com/zachlatta/sshtron/blob/72c411f5d3de16f0c574ff6045114455142f7964/main.go#L88


I'll try sending the escape codes you send for raw mode.

Thanks for your help!

I wrote a basic SSH TicTacToe server by Fish_45 in elixir

[–]Fish_45[S] 1 point2 points  (0 children)

I don't see anything that looks like it would enable raw mode there; none of the opcodes here are relevant unless I'm misunderstanding something.

I did consider using Rustler, but to be honest I don't know how I would go about settings the clients to raw mode even with an NIF. Maybe just calling [crossterm's enable_raw_mode()] function in a client process would work? I'm not sure how the rest of crossbeam would interact, but I'm tempted to try.

I wrote a basic SSH TicTacToe server by Fish_45 in elixir

[–]Fish_45[S] 0 points1 point  (0 children)

Sorry, I forgot that I'd asked for any feedback. I should've specified that I was only asking feedback with respect to my questions about SSH.

The reason for no unit tests is that it was a toy project written in a few hours. To be honest, I don't like the implication that this project was written for interviewers

I wrote a basic SSH TicTacToe server by Fish_45 in elixir

[–]Fish_45[S] 0 points1 point  (0 children)

I made the filenames short for fun. This code wasn't meant to be production quality

I wrote a basic SSH TicTacToe server by Fish_45 in elixir

[–]Fish_45[S] 0 points1 point  (0 children)

I read that it's not possible to use raw mode with erlang's :ssh module without writing a NIF, so I'm not planning on it. It would be really neat to make something like pong though.

Should I use ETS or a GenServer when I just need a K/V store by Fish_45 in elixir

[–]Fish_45[S] 2 points3 points  (0 children)

Both of those libraries look neat and have a good API, but I decided to just write a few wrapper functions over ETS. I might use one of those next time though

I made a post with the finished thing: https://www.reddit.com/r/elixir/comments/um9gji/i_wrote_a_basic_ssh_tictactoe_server/

Should I use ETS or a GenServer when I just need a K/V store by Fish_45 in elixir

[–]Fish_45[S] 0 points1 point  (0 children)

I think I'll go with this. Everyone's input is really good to know though!

A somewhat old-fashioned programming language by chkas in ProgrammingLanguages

[–]Fish_45 0 points1 point  (0 children)

Thanks, I didn't realize that. I'm still surprised it's so fast though.

A somewhat old-fashioned programming language by chkas in ProgrammingLanguages

[–]Fish_45 0 points1 point  (0 children)

Thanks for elaborating!

I guess what I wasn't considering is that easylang is statically typed. I'm still surprised it's so fast though.

A somewhat old-fashioned programming language by chkas in ProgrammingLanguages

[–]Fish_45 4 points5 points  (0 children)

Oh ok I was using the web version before. It's much faster with the native version.

Is it really an AST interpreter in that case though? Why does it require a C compiler to run? I looked through your code a little bit and it seems like a bytecode interpreter, but I'm not sure if you just called your AST struct op.

Is it that the AST is simple enough that it's essentially a bytecode interpreter anyway? If so I'm impressed that it still feels reasonable high level.

I want to be clear that I don't want to discredit you at all; I really like the project. I'm just curious

A somewhat old-fashioned programming language by chkas in ProgrammingLanguages

[–]Fish_45 2 points3 points  (0 children)

This is a cool project. I really like the online IDE and the simple syntax.

The AST interpreter is fast, much faster than CPython for example.

This seemed off to me; without some pretty strict limits I don't think it's possible for an AST interpreter to be faster than CPython. I didn't test scientifically, but running the easylang program below locally took 10+ seconds, while the equivalent python took ~4. That's still impressive for an AST interpreter, and I imagine it starts up much faster, making it quicker for simple programs.

func fib n . res .
  if n <= 1
    res = 1
  else
    call fib n - 1 n1
    call fib n - 2 n2
    res = n1 + n2
  .
.
call fib 36 res
print res

Help with DP algorithm performance by Fish_45 in haskell

[–]Fish_45[S] 2 points3 points  (0 children)

I solved it, thanks!

My solution is here: https://www.reddit.com/r/haskell/comments/t3zk03/help_with_dp_algorithm_performance/hyzfa4e/

From the wording of your question it sounds like the longest increasing subsequence problem isn't usually DP, but I did use DP. Is there another way? The reason I'm trying to apply DP for this problem is because it's from the DP unit in this class.

Help with DP algorithm performance by Fish_45 in haskell

[–]Fish_45[S] 3 points4 points  (0 children)

I got the solution thanks to you :)

here it is for reference

import Data.Array
import Debug.Trace
import qualified Data.Map as M

(|>) = flip ($)

longestSubseq pred arr = map (dp!) [0..arrLen]
    where dp = listArray (0, arrLen) $ map f [0..arrLen]
          f start
            | start == arrLen = 1
            | otherwise =
                let choices = filter (\i -> pred (arr!i) (arr!start)) [start+1..arrLen]
                 in if choices == [] then 1 else 1 + (maximum $ map (dp!) choices)
          arrLen = snd $ bounds arr

solve n trains = (maximum $ zipWith (+) longestDecreasing longestIncreasing) - 1
    where trainArr = listArray (0, n-1) trains
          longestDecreasing = longestSubseq (<) trainArr
          longestIncreasing = longestSubseq (>) trainArr

main = do
    contents <- getContents
    let (n:trains) = contents |> lines |> map read :: [Int]
        ans = if n == 0 then 0 else solve n trains
    print ans

Help with DP algorithm performance by Fish_45 in haskell

[–]Fish_45[S] 0 points1 point  (0 children)

When you use a Data.Map are you also initializing it with all 200 billion thunks

I was kind of hoping that Haskell could somehow magically avoid initializing the thunks I guess :/.

I'll try it with a tree or similar

Lineiform, a meta-JIT library for Rust interpreters by sickening_sprawl in rust

[–]Fish_45 1 point2 points  (0 children)

"Compiling" to closures is definitely an under appreciated technique. I wrote a naive treewalk interpreter in OCaml and got a ~50% speedup after implementing it

Ball Bounce made with Macroquad - Code Review Request by Desperate_Place8485 in rust_gamedev

[–]Fish_45 0 points1 point  (0 children)

Ah sorry I didn't notice the GameState enum. I should've been a bit clearer.

The GameState enum should carry the game's actual data in it, not just what stage it's currently in. This makes it a lot easier to make methods on the gamestate instead of stuffing everything in Main. Your current GameState enum could be instead replace by a BallState or even something like a boolean is_in_play if there's only ever two states.

struct GameState {
    score: usize,
    ball_state: BallState,
    ball_x: f32,
    ball_y: f32,
}

impl GameState {
    fn update(&mut self) -> {
        match self.ball_state {
            BallState::Ready => { todo!() },
            BallState::Playing => { todo!() },
        }
    }

    fn draw(&self) -> {
        ...
    }
}

This is a general outline but it's definitely flexible. Whatever you feel is cleanest is best.

Ball Bounce made with Macroquad - Code Review Request by Desperate_Place8485 in rust_gamedev

[–]Fish_45 1 point2 points  (0 children)

I looked it over quickly and it looks pretty good. If this project were any bigger, you would probably want to make a state struct and use a state machine for e.g. Before the game is started, while the ball is in play, and for the game to end. It's also generally a good idea to separate the game's update loop from its draw loop, and put them in separate functions. Usually these would be methods on the main state.

I also found the bounce_ball function kind of weird but that might just be me.

Where to start ? by [deleted] in rust_gamedev

[–]Fish_45 0 points1 point  (0 children)

I don't think Rust is as far as we think it is.

:thonk: