havenwood changed the topic of #ruby to: Ruby 3.4.5, 3.3.9, 3.5.0-preview1 https://www.ruby-lang.org | Log https://libera.irclog.whitequark.org/ruby
<kmad> weaksauce: I'm guessing it's this one: https://rubygems.org/gems/io-stream
<weaksauce> kmad good call
ih8u2 has joined #ruby
ih8u has quit [Ping timeout: 252 seconds]
ih8u2 is now known as ih8u
ih8u2 has joined #ruby
ih8u has quit [Ping timeout: 244 seconds]
ih8u2 is now known as ih8u
cappy has joined #ruby
chair1 has quit [Ping timeout: 252 seconds]
Linux_Kerio has quit [Ping timeout: 240 seconds]
cappy has quit [Quit: Leaving]
jankasi has joined #ruby
Fusl has quit [Quit: K-Lined]
Fusl has joined #ruby
jmcantrell has joined #ruby
jmcantrell has quit [Ping timeout: 252 seconds]
shiru has joined #ruby
shiru` has joined #ruby
shiru has quit [Ping timeout: 260 seconds]
_whitelogger has joined #ruby
Linux_Kerio has joined #ruby
Linux_Kerio has quit [Read error: Connection reset by peer]
shiru``` has joined #ruby
shiru`` has quit [Ping timeout: 276 seconds]
shiru```` has joined #ruby
shiru``` has quit [Ping timeout: 272 seconds]
grenierm has joined #ruby
shiru```` has quit [Ping timeout: 272 seconds]
_whitelogger has joined #ruby
finsternis has quit [Ping timeout: 240 seconds]
dorian has quit [Ping timeout: 240 seconds]
dorian has joined #ruby
finsternis has joined #ruby
grenierm has quit [Ping timeout: 252 seconds]
<tsujp> havenwood o0x1eef TIL Data class, I've been using Struct for stuff like that
sweatiest has quit [Quit: ZNC 1.9.1+deb2+b3 - https://znc.in]
sweatiest has joined #ruby
<o0x1eef> As an aside, with Kernel.spawn + IO.pipe you solve the problem with "core" Ruby classes and objects - there is nothing to require. With Open3 you depend on the stdlib, and with io/stream you depend on an external gem.
Quiet-Oil9262 has quit [Quit: The Lounge - https://thelounge.chat]
<o0x1eef> I still use Struct for stuff like that :)
Quiet-Oil9262 has joined #ruby
cappy has joined #ruby
<tsujp> yeah im experimenting with trying to use core ruby classes only and then ill do a little benchmark versus open3 and that io/stream gem
<tsujp> this tiny example doesn't even work though.. it just hangs forever with ruby 3.4.5.. what am I doing wrong? https://gist.github.com/tsujp/0ab5647d5b3e081f75fc125852db20cd
<o0x1eef> One sec and I will set the script up locally
<tsujp> Why do I need to put it into a Struct as you have?
<o0x1eef> IO.pipe returns an array. The first element is a socket used for read operations, and the second socket is a socket used for write operations.
<o0x1eef> It's not required - it could also be stdout[0] (reader) and stdout[1] (writer). reader, writer = IO.pipe also works.
inline has quit [Remote host closed the connection]
<tsujp> Oh hang on, the sockets are for read and write derp
<tsujp> Lemme try again without the Struct
inline has joined #ruby
cappy has left #ruby [Leaving]
<o0x1eef> Sounds good. The fix though is "stdout.w.close". You could also not try to read to the end to fix that (eg stdout.r.read(1)).
foxxx0 has quit [Quit: foxxx0]
foxxx0 has joined #ruby
<o0x1eef> Looks good to me. You could also use Process.detach on the PID to setup a thread that will collect the status. From there you have streams to communicate with the process. Avoid .read(nil) if you don't want to be forced to close the stream.
<tsujp> In this case I am executing a bunch of short-lived commands, for longer running stuff I'd agree. This is also probably HUGE overkill but it's a good opportunity to try a different approach/learn
<tsujp> I'm trying to make a little DSL for it too... is there a way to loop each line of a block lol?
<o0x1eef> Not sure I follow what you mean
<tsujp> o0x1eef: im trying to do something like this https://gist.github.com/tsujp/4f4ecdc2d68f844b689a37ec9e2f0c7f
<tsujp> each of those `set` lines is it's own Process.spawn
<o0x1eef> Why not turn "set" into a method?
<tsujp> Ah yeah with set I think I will, but imagine without set
<tsujp> I guess it would work without set too.. method_missing approach?
<o0x1eef> It could, yeah. Quite often DSLs are implemented that way in Ruby.
<o0x1eef> You could also define the verbs of the "language" (set, etc) as methods, and then you can easily hook those up to Kernel.spawn or whatever the case might be.
<tsujp> I think `set` as a method makes this easier and less clunky so that's my plan for now
<o0x1eef> Sounds good
<tsujp> im stuck trying to get set working, it seems to be ignoring it completely
<tsujp> i get undefined method 'InitialKeyRepeat' for module Defaults (NoMethodError): set InitialKeyRepeat int: 10
<tsujp> if I change set to setz (in the block) its the same error, so its ignoring it completely?
<tsujp> I do need access to prior args within each instance_eval.. so I guess this needs to be a class and not a module?
<o0x1eef> The code appears to be good. The issue is with the argument to 'set'. That's not valid syntax. set InitialKeyRepeat(int: 10) might be what you want?
<o0x1eef> or set 'InitialKeyRepeat', int: 10
<tsujp> Ah I cannot use it like that ok, or I could but it'd need method_missing stuff
<tsujp> Could do it as function params.. is this viable tho: Foo(int: 10) Foo(false) Foo(float: 1.23) Foo('Centimeters')
<tsujp> AFAIK you couldn't have all those variations possible while still looking like that, no?
<o0x1eef> Exactly. This works.
<tsujp> Oh it will work ok ok
<o0x1eef> You could then hook up method_missing to understand 'Foo', or just implement Foo as a method (def Foo(...); end)
user71 has joined #ruby
<tsujp> Okay this is coming along a bit, unsure how to access "prior" block values. Need to re-read instance_eval
<o0x1eef> Probably a good use-case for the set or domain commands to be stateful
gr33n7007h has quit [Quit: WeeChat 4.7.0]
gr33n7007h has joined #ruby
chair1 has joined #ruby
chair1 has quit [Ping timeout: 252 seconds]
<tsujp> o0x1eef: here's the DSL working (getting the eventual data to form a correct command) https://gist.github.com/tsujp/b5da88cc3f8b58a8d7eaa6f999594be7
<tsujp> if you run that code you'll see the stuff printed to stdout, I think I'll have it run all these and return back actual values which are then iterated on
<tsujp> or I can just have set immediately go the threading stuff when it then has the correct command
<o0x1eef> Pretty cool! Congrats
<o0x1eef> I like this style: set InitialKeyRepeat 10
chair1 has joined #ruby
<tsujp> hehe cheers
<tsujp> So the Process.detatch would be instead of Thread.new right?
chair1 has quit [Quit: Client closed]
gr33n7007h has quit [Ping timeout: 244 seconds]
pages has quit [Quit: ZNC - https://znc.in]
gr33n7007h has joined #ruby
pages has joined #ruby
<o0x1eef> Process.detach would be given the return value of Process.spawn, eg: Process.detach Process.spawn("ls", ...).
<o0x1eef> And yep - it could replace Thread.new since Process.detach covers it now
<tsujp> Do I go the route of trying to implement a simple thread pool now hehueuhe
<tsujp> Cos there will be about 100-ish commands to run.. not sure if 100 threads would be allowed
<o0x1eef> I mean, you could do it with one thread :) pids = []; pids << Process.spawn(...); pids.each { Process.wait(_1) }
<tsujp> true true
<tsujp> all this instead of just having a bog-standard shell script (but it's fun exploring this and not mission critical at all so.. better time than most I'd say)
<tsujp> gotta over engineer to the max >:)
<o0x1eef> It's fun :)
pages has quit [Remote host closed the connection]
pages has joined #ruby
chair1 has joined #ruby
rvalue- has joined #ruby
rvalue has quit [Ping timeout: 248 seconds]
rvalue- is now known as rvalue
blacknova has joined #ruby
jmcantrell has joined #ruby
cappy has joined #ruby
user71 has quit [Quit: Leaving]
chair1 has quit [Quit: Client closed]
fantazo has joined #ruby
fantazo has quit [Changing host]
fantazo has joined #ruby
jmcantrell has quit [Ping timeout: 248 seconds]
The_Camel has quit [Remote host closed the connection]
The_Camel has joined #ruby
ruby[bot] has quit [Remote host closed the connection]
ruby[bot] has joined #ruby
pages has quit [Remote host closed the connection]
pages has joined #ruby
cappy has quit [Quit: Leaving]
fantazo has quit [Quit: Lost terminal]
blacknova has quit [Quit: Connection closed for inactivity]
chair1 has joined #ruby