ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
straight-shoota has quit [Quit: ZNC 1.8.2 - https://znc.in]
straight-shoota has joined #crystal-lang
phuncmain has quit [Quit: WeeChat 2.8]
richbridger has joined #crystal-lang
aquijoule_ has quit [Ping timeout: 272 seconds]
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 260 seconds]
<FromGitter> <watzon> I thought you could bind a socket to a random port by setting the port as `0` and letting the system choose. Is it not supposed to be `0`?
<FromGitter> <Blacksmoke16> `HTTP::Server` has https://crystal-lang.org/api/master/HTTP/Server.html#bind_unused_port(host:String=Socket::IPAddress::LOOPBACK,reuse_port:Bool=false):Socket::IPAddress-instance-method
<FromGitter> <Blacksmoke16> which is implemented via using `0` as the port
<FromGitter> <watzon> So weird
<FromGitter> <watzon> When I try to `.bind("127.0.0.1", 0)` I get ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=602b4c419403f11bb586c896]
<FromGitter> <Blacksmoke16> what if you do `"0.0.0.0"`
<FromGitter> <Blacksmoke16> i doubt that'll change anything tho
<FromGitter> <watzon> Yeah it doesn't, already tried
<FromGitter> <Blacksmoke16> sec
<FromGitter> <Blacksmoke16> yea i dunno
sz0 has quit [Quit: Connection closed for inactivity]
sz0 has joined #crystal-lang
Human_G33k has joined #crystal-lang
HumanG33k has quit [Ping timeout: 272 seconds]
f1reflyylmao is now known as f1refly
entel has quit [Quit: Connection closed for inactivity]
<FromGitter> <naqvis> you should try `bind_tcp`
<FromGitter> <naqvis> like `.bind_tcp(Socket::IPAddress.new("127.0.0.1", 0))`
<FromGitter> <naqvis> below snippet works ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=602b74038621811d587d67e2]
entel has joined #crystal-lang
_ht has joined #crystal-lang
Flipez7 has joined #crystal-lang
alexherbo2 has joined #crystal-lang
Flipez has quit [Read error: Connection reset by peer]
Flipez7 is now known as Flipez
<FromGitter> <erdnaxeli:cervoi.se> hi, can I do a case in a macro ?
<FromGitter> <erdnaxeli:cervoi.se> like {% case test %}
<FromGitter> <erdnaxeli:cervoi.se> it seems to complains
deavmi has quit [Quit: Eish! Load shedding.]
deavmi has joined #crystal-lang
<FromGitter> <naqvis> don't believe you can do that, afaik `if` is the only conditional expression which can be used inside macros.
<FromGitter> <erdnaxeli:cervoi.se> ok thanks
deavmi has quit [Quit: Eish! Load shedding.]
deavmi has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 264 seconds]
aquijoule_ has joined #crystal-lang
richbridger has quit [Ping timeout: 272 seconds]
DTZUZU__ is now known as DTZUZU
Human_G33k has quit [Remote host closed the connection]
Human_G33k has joined #crystal-lang
deavmi has quit [Ping timeout: 265 seconds]
alexherbo2 has joined #crystal-lang
deavmi has joined #crystal-lang
deavmi has quit [Ping timeout: 240 seconds]
deavmi has joined #crystal-lang
<FromGitter> <watzon> @naqvis problem is I'm using TCPSocket directly, not HTTP::Server
<FromGitter> <watzon> I think I figured the problem out though. I was attempting to connect and then bind. It seems to work if I bind first and then connect.
<FromGitter> <rukkiddo> is there a shorthand for hashes like js have for objects?
<FromGitter> <rukkiddo> in js {a} is actually {"a":a}
<FromGitter> <Blacksmoke16> no
<FromGitter> <rukkiddo> do you think is it possible to emulate it with function
<FromGitter> <rukkiddo> like array to hash
<FromGitter> <Blacksmoke16> probably but is it really worth it?
<FromGitter> <rukkiddo> if I give [a] can it convert it to {"a":a}
<FromGitter> <rukkiddo> well it depends
<FromGitter> <watzon> You could do it with a tuple instead and maintain the curly brace syntax, but you'd have to monkey patch `Tuple` with a method and then call that method, there wouldn't really be a way to do it automatically
<FromGitter> <watzon> Actually... you'd probably need a macro come to think of it
<FromGitter> <Blacksmoke16> hardly seems worth the extra complexity
<FromGitter> <watzon> Yeah it's something that would be better supported at the compiler level, but it won't happenm
<FromGitter> <rukkiddo> i dont really understand why, but the same request was also rejected by ruby community
<FromGitter> <rukkiddo> I thought it is convenient for some cases but it is ok
<FromGitter> <Blacksmoke16> arbitrary objects arent as common in crystal land
<FromGitter> <Blacksmoke16> plus there would be some confusion as to how exactly this would work
<FromGitter> <Blacksmoke16> i.e. `{a}` should that be expanded to a named tuple/hash, or is a tuple of one element
<FromGitter> <rukkiddo> yeah current literals are deal breaker in this case
<FromGitter> <rukkiddo> still I will agree to disagree I guess
<FromGitter> <Blacksmoke16> i mean dont get me wrong i like the feature in TS/JS land, but i dont really find myself needing as often in Crystal land
eax has joined #crystal-lang
eax has quit [Client Quit]
eax has joined #crystal-lang
eax has quit [Client Quit]
eax has joined #crystal-lang
<FromGitter> <watzon> Same, tbh I would much rather have named tuple destructuring
<FromGitter> <watzon> Or indirect initialization be supported
<FromGitter> <watzon> I don't get why it isn't right now
eax has quit [Client Quit]
eax has joined #crystal-lang
Human_G33k has quit [Ping timeout: 240 seconds]
Human_G33k has joined #crystal-lang
<FromGitter> <alexherbo2> is there a way to transfer `stdin` to a named pipe (fifo)?
<FromGitter> <oprypin:matrix.org> @alexherbo2: i dont know if it will work but try `STDIN.reopen(that)`
<FromGitter> <alexherbo2> the use case is to send a command (in a session of an editor) to open a fifo, which have access to the stdin from the command-line
<FromGitter> <oprypin:matrix.org> @alexherbo2: interesting use case. but can't you *just* launch it with Process.new?
<FromGitter> <alexherbo2> @oprypin:matrix.org the editor can only access the fifo
<FromGitter> <oprypin:matrix.org> `specify, stdin: :pipe`
<FromGitter> <alexherbo2> in an old code I used reopen
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=602c2690e634904e60a40a9f]
<FromGitter> <alexherbo2> not sure if there was a shorthand to it
<FromGitter> <oprypin:matrix.org> @alexherbo2: i don't understand. does your code already work or not?
<FromGitter> <alexherbo2> @oprypin:matrix.org I don't think `Process.new` can work, it's the command-line language of the editor
<FromGitter> <oprypin:matrix.org> i dont think there is a shorthand
<FromGitter> <oprypin:matrix.org> so *your program* wants to send stuff to the editor?
<FromGitter> <oprypin:matrix.org> you said ⏎ ⏎ > which have access to the stdin from the command-line ⏎ ⏎ i thought you wanted to expose that to a human [https://gitter.im/crystal-lang/crystal?at=602c271e8621811d587f603c]
<FromGitter> <alexherbo2> my code works, but I haven't implemented the `fifo` command yet
<FromGitter> <oprypin:matrix.org> @alexherbo2: forget about pipe
<FromGitter> <alexherbo2> ```kak -s kanto <<EOF ⏎ edit -fifo /path/named/pipe *fifo* ⏎ EOF``` [https://gitter.im/crystal-lang/crystal?at=602c27b2dc108172e77f4860]
<FromGitter> <oprypin:matrix.org> you just want `Process.new(stdin: :pipe)`
<FromGitter> <oprypin:matrix.org> if creating a *named* pipe is not one of your requirements, (rather just a way to achieve goal), i'm telling you that your goal has easier ways to achieve
<FromGitter> <alexherbo2> what does `:pipe`?
<FromGitter> <oprypin:matrix.org> `pr = Process.new(stdin: :pipe); pr.stdin << "whatever commands"`
<FromGitter> <alexherbo2> wow :o
<FromGitter> <alexherbo2> I was always using `STDIN` / `STDOUT` refs, which I was not happy
<FromGitter> <alexherbo2> thanks for the trick
<oprypin> what you were doing is more of a trick 😂
<FromGitter> <oprypin:matrix.org> oops switched chat client again
<FromGitter> <alexherbo2> the thing is the session, which I send the command, has not access to the stdin/stdout I give with `Process`
<FromGitter> <alexherbo2> that's why I wanted a fifo, so that the editor can acceed that path
_ht has quit [Remote host closed the connection]
<FromGitter> <alexherbo2> how to alias methods?
<FromGitter> <Blacksmoke16> dont
<FromGitter> <alexherbo2> ``` def with_fifo(&block : Path ->) ⏎ with_fifo_read(&block) ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=602c3d7c8031c8234be65ae8]
<FromGitter> <Blacksmoke16> alias it to what?
<FromGitter> <alexherbo2> `with_fifo` to `with_fifo_read`
<FromGitter> <Blacksmoke16> thats what you would do yes
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=602c3dc79403f11bb589590e]
<FromGitter> <alexherbo2> I tried `File.new("path/to/fifo")` but it was blocking
teardown has quit [Ping timeout: 268 seconds]
teardown has joined #crystal-lang
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=602c537ea8c6a7784813d14f]
<FromGitter> <alexherbo2> I wanted to do something like that
<FromGitter> <alexherbo2> I looked at the crystal code but the initializer using `blocking` parameter is private
<FromGitter> <alexherbo2> it could be nice to detect the file is a fifo to not block by default
<FromGitter> <alexherbo2> or tempfile to create fifos
alexherbo2 has quit [Ping timeout: 240 seconds]