jhass changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.28.0 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
<FromGitter> <Blacksmoke16> do you just read the data in `/dev/ttyUSB0`?
<FromGitter> <Blacksmoke16> could use `gets_to_end`which would read the data at once as a string
<FromGitter> <asterite> when `gets` doesn't have anything to read and it's not the end, it blocks and another fiber executes
<FromGitter> <asterite> I tried it on my machine with a regular file (not a socket) and it works fine, so maybe the problem is related to the file being a socket
<FromGitter> <asterite> but I don't have `/dev/ttyUSB0` on my machine so I can't try it
<FromGitter> <omidathari> That is exactly what i expected
<FromGitter> <omidathari> @asterite I've gotten that to work perfectly for udp/tcp sockets, but for some reason with this serial fd calling `gets` seems to interfere with stdin.
<FromGitter> <Blacksmoke16> gets waits for input from STDIN
alexherbo25 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 246 seconds]
<FromGitter> <omidathari> @Blacksmoke16 exactly. My problem is that `gets` blocks as expected and the fiber runs. But when `sf1.gets` is called it hangs instead of blocking and allowing input from stdin to be picked up by gets.
<FromGitter> <Blacksmoke16> yea sadly we're at the extend of my knowledge on this area :/
<FromGitter> <Blacksmoke16> maybe someone else knows
<FromGitter> <omidathari> @asterite It seems like calling gets on a TTY file descriptor hangs instead of blocks. We've already tried breaking these out into different files instead of fibers and letting the OS handle concurrency. Not a great solution but it works. Do you have any suggestion?
prettyrobots has joined #crystal-lang
prettyrobots is now known as sympatico
<FromGitter> <tenebrousedge> is there any way to test this on Unix without having the hardware?
<FromGitter> <Blacksmoke16> vm?
<FromGitter> <tenebrousedge> seems a bit heavy, maybe this: https://stackoverflow.com/questions/52187/virtual-serial-port-for-linux
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <pynixwang> must be (Array(Array(String) | String | Nil) | Nil), not Array(String)
<FromGitter> <pynixwang> Array(String) is not (Array(Array(String) | String | Nil) | Nil) ?
<FromGitter> <Blacksmoke16> nope
<FromGitter> <pynixwang> compatable?
<FromGitter> <Blacksmoke16> could do like `["str"] of Array(Array(String) | String | Nil`
<FromGitter> <pynixwang> try
<FromGitter> <pynixwang> not ok
<FromGitter> <pynixwang> union type is tricky.
<FromGitter> <Blacksmoke16> got example code?
<FromGitter> <pynixwang> topics
<FromGitter> <pynixwang> arg type is `Array(Array(String) | String | Nil)`
<FromGitter> <pynixwang> ["xxx"] is valid
<FromGitter> <pynixwang> but why
<FromGitter> <pynixwang> it Array(String)
<FromGitter> <pynixwang> 's
<FromGitter> <Blacksmoke16> but its not the same type
<FromGitter> <pynixwang> function args is ok
<FromGitter> <pynixwang> instance var is not ok
<FromGitter> <Blacksmoke16> yes
<FromGitter> <Blacksmoke16> could need to tell it your array is of the same type
<FromGitter> <pynixwang> `as` and `of` also not ok
<FromGitter> <Blacksmoke16> Got a simple example?
<FromGitter> <pynixwang> yes
<FromGitter> <pynixwang> [["xxxxx"], "", nil]
<FromGitter> <pynixwang> this work
<FromGitter> <pynixwang> but not what I want
<FromGitter> <Blacksmoke16> just do `["str"] of Array(String) | String | Nil`
<FromGitter> <pynixwang> work
<FromGitter> <Blacksmoke16> šŸ‘
moei has joined #crystal-lang
<FromGitter> <pynixwang> thanks.
<FromGitter> <pynixwang> why method arg is compatable, but ivar not work?
<FromGitter> <Blacksmoke16> ivar type restrictions are more strict
<FromGitter> <pynixwang> this can be write to doc.
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <advancedwebdeveloper> hello
<FromGitter> <advancedwebdeveloper> which option exist for deploying micro-serices, FaaS "functions" for Crystal
<FromGitter> <advancedwebdeveloper> ?
<FromGitter> <advancedwebdeveloper> any plans to support MIPS arch?
<FromGitter> <bararchy> @advancedwebdeveloper -> https://faastruby.io/
<FromGitter> <straight-shoota> @vladfaust Are you available? We're waiting on the hangout =)
<FromGitter> <vladfaust> I am woke!
<FromGitter> <vladfaust> Iā€™m wok with noodles
<FromGitter> <vladfaust> Sorry I did not see those forum posts after my message
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
sz0 has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
relyks has joined #crystal-lang
relyks has quit [Client Quit]
DTZUZO has quit [Ping timeout: 255 seconds]
tdc has quit [Quit: Leaving]
ashirase has quit [Ping timeout: 252 seconds]
ashirase has joined #crystal-lang
Vexatos has quit [Remote host closed the connection]
Vexatos has joined #crystal-lang
DTZUZO has joined #crystal-lang
<FromGitter> <mavu> is there a way to break out of a case? something like āŽ āŽ ```case sdf``` [https://gitter.im/crystal-lang/crystal?at=5cde897983ae782aee81e546]
alexherbo25 has quit [Ping timeout: 245 seconds]
alexherbo25 has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <straight-shoota> No, `case` is essentially just a different way of writing a series of `if ... elsif`. So you need to use regular control flow mechanics.
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <mavu> ok, thanks
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
tankf33der has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6xk7 shouldnt this create an empty hash with the type i gave it?
<FromGitter> <Blacksmoke16> works fine if you remove the nested hash
<jokke> any obvious reason why HTTP::Server doesn't support listening on file descriptors?
<FromGitter> <mwlang> @asterite and @Blacksmoke16 Thanks for the pointers on using select. I had to spend some time to get to understand that one. I don't think select is my problem, though. I reduced the code further to just running one Listener and I still had an issue with breaking out of the spawned run loop, this time when the websocket received an unexpected message.
<FromGitter> <Blacksmoke16> np, what does it do? :p
<jokke> i'd like to experiment with socket activated systemd services
<FromGitter> <mwlang> I have solved the unexpected message issue by attempting to parse JSON with rescue block.
<FromGitter> <mwlang> what does select do? It lets you listen for more than one channel update at once.
<FromGitter> <yxhuvud> listening on socket files would make sense. listening on other type of files perhaps not so.
<FromGitter> <Blacksmoke16> hmm, gotcha
<FromGitter> <mwlang> @Blacksmoke16 that play looks like a recursive / circular reference sort of issue.
<FromGitter> <straight-shoota> jokke, HTTP::Server supports UNIX sockets and for regular use cases you won't need more anyway
<jokke> i see
<FromGitter> <Blacksmoke16> yea but its still a valid type no?
<FromGitter> <Blacksmoke16> just would allow the hash to have a hash as a property and so on
<FromGitter> <mwlang> far as I know!
<FromGitter> <mwlang> can you add to a union after it's been declared?
<FromGitter> <straight-shoota> If you want to listen on an arbitrary file descriptor, you could just implement a `Socket::Server` for this and bind it to the server. Maybe `http_server.bind UNIXServer.new(fd: file_descriptor)` would already be enough.
<FromGitter> <mwlang> This got the same error as well: https://play.crystal-lang.org/#/r/6xku
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6xkx is just when the alias is the hash
<FromGitter> <straight-shoota> jokke, Alternatively, if you only need to serve a single connection anyway, you could use `HTTP::RequestProcessor` directly with a `IO::Filedescriptor`
<FromGitter> <mwlang> There we go. That's what I'd do anyway. Reads better.
<jokke> hm yeah idk
<FromGitter> <Blacksmoke16> ehh thats what im doing now but id rather do like `@context : LogContext := LogContext.new`
<FromGitter> <Blacksmoke16> but meh
<jokke> straight-shoota: then stuff like Connection: keepalive wouldn't work i suppose
<FromGitter> <straight-shoota> Why not?
<jokke> would HTTP::RequestProcessor handle multiple requests?
<jokke> i'll just give it a try :)
livcd has quit [Quit: Lost terminal]
livcd has joined #crystal-lang
<jokke> sweet
<jokke> it works like a charm
livcd has quit [Read error: Connection reset by peer]
<FromGitter> <pynixwang> sleep main Fiber other fibers execute more?
<FromGitter> <Blacksmoke16> doing a `sleep` in main fiber would cause main fiber to block, thus allowing other fibers to execute
<FromGitter> <bararchy> Fiber.yield :)
<FromGitter> <pynixwang> I want main Fiber to be a watch dog
<FromGitter> <pynixwang> sleep 100 second then check other fibers
<FromGitter> <pynixwang> are there any general fiber manager?
<FromGitter> <mwlang> Is this a general "Exception" error? I want to capture and handle gracefully, but I'm not sure if the exception class is "Exception" or it is... āŽ āŽ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cdec0c3509b1035c7647661]
<FromGitter> <Blacksmoke16> is `Errno`
<FromGitter> <mwlang> So what's in parentheses is the class name of the exception?
<FromGitter> <Blacksmoke16> it inherits from `Exception`
<FromGitter> <Blacksmoke16> yea
<FromGitter> <pynixwang> 500 fiber cpu 100%
<FromGitter> <mwlang> ok, that explains the source I was looking at, too: āŽ āŽ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cdec13e879f4478c79598d5]
<FromGitter> <Blacksmoke16> ye, would be an exception thrown from the c lib
<FromGitter> <mwlang> So how do I make use of the constants defined in the Errno module? For example, To handle specifically a peer reset in Ruby, it would be ```rescue Errno::ECONNRESET => e```
<FromGitter> <Blacksmoke16> maybe like `rescue Errno` then a case based on the response?
<FromGitter> <mwlang> hmmm...and just re-raise the error in a case's else clause?
<FromGitter> <Blacksmoke16> something like
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cdec2e60ac9852a95f37631]
laaron has joined #crystal-lang
<FromGitter> <Blacksmoke16> assuming you wanted to catch a specific error, could catch the ones you want then handle rest in the else block
<FromGitter> <mwlang> ok, that's what I thought you were suggesting.
<FromGitter> <mwlang> oh, boy...now I gotta figure out how to re-launch a spawned run... ie. ```spawn { @ws.run }```
<FromGitter> <Blacksmoke16> :shrug:
tdc has joined #crystal-lang
<FromGitter> <mwlang> I cannot quite figure out how to detect when a spawned fiber goes away so that another loop can detect this and also exit it's fiber.
<FromGitter> <mwlang> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cdecaf59404bf2aed618f16]
<FromGitter> <mwlang> specifically where I have "exit" in the rescue block...I want to stop the fiber and simultaneously somehow signal to the while ```line = channel.receive?``` that this fiber is no longer running
<FromGitter> <jgaskins> The only way I've gotten this work is by setting a shared variable. āŽ āŽ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cdecbce509b1035c764d5bb]
<FromGitter> <tenebrousedge> does `spawn` have a return value? the `Fiber` class does have `dead?` and `running?`
<FromGitter> <jgaskins> Also, hi @mwlang! šŸ‘‹ :-D
<FromGitter> <mwlang> Hi, @jgaskins :-D
<FromGitter> <mwlang> ok, so I iterated this but it seems so wrong to utilize the channel itself to communicate a dead fiber: https://play.crystal-lang.org/#/r/6xlr
<FromGitter> <mwlang> So, are you messing around with crystal these days, @jgaskins?
<FromGitter> <z64> @mwlang yes that is the way to handle this - using channels to communicate, and just letting the fiber exit and be collected when its done āŽ āŽ you can utilize some types to make this more useful https://play.crystal-lang.org/#/r/6xlw
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <mwlang> @z64 thanks for that! I did not even think about types other than Strings, so yes, this makes it feel a lot cleaner in implementation
<FromGitter> <z64> yw šŸ‘
<FromGitter> <jgaskins> @mwlang Yeah, I've been building a few things with it. :-) Trying to work a few microservices to use it at work, but I've also been working on a few other projects, like a Neo4j driver and a port of Phoenix LiveView.
<FromGitter> <mwlang> Ah, your love of graph databases. :-D Sounds like fun with the Neo4j driver. As for micro-services, that's where I'm at as well -- replacing a few slow running Ruby data collectors with Crystal equivalents.
<FromGitter> <tenebrousedge> @jgaskins what do you love about graph databases/neo4j ?
<FromGitter> <mwlang> I think I'll go ahead and start my first open source crystal contribution...writing binance api library wrappers (https://github.com/binance-exchange/binance-official-api-docs) I've just been doing this in raw form as I learn Crystal, but writing a shard can help me learn Crystal a bit more formally, I think.
<FromGitter> <mwlang> What do y'all use most for automated spec runs like Ruby's guard? I see more than a few choices referenced on https://github.com/veelenga/awesome-crystal#development-tools
<FromGitter> <Blacksmoke16> up arrow enter :p
<FromGitter> <mwlang> also, for unit/integration testing, will want something like Ruby's VCR gem (https://github.com/vcr/vcr)
<FromGitter> <mwlang> @Blacksmoke16 yeah, yeah, yeah -- I'm l-a-z-y. :-)
<FromGitter> <Blacksmoke16> šŸ˜‰
<FromGitter> <dscottboggs_gitlab> I feel like I'm missing something obvious here... https://carc.in/#/r/6xm0
<FromGitter> <Blacksmoke16> šŸ˜¬
<FromGitter> <dscottboggs_gitlab> what?
<FromGitter> <Blacksmoke16> i have no idea whats going on :S
<FromGitter> <dscottboggs_gitlab> lol oh I thought it was really obvious and you knew right away
<FromGitter> <dscottboggs_gitlab> but that sort of response was why I thought the answer "use `OpenSSL::Cipher`" was an inadequate answer to the question "how do I encrypt something"
<FromGitter> <dscottboggs_gitlab> like there should be a shard that lets you do `Object#encrypt` and `Object.decrypt`
<FromGitter> <jgaskins> @tenebrousedge I love SQL but it's not super expressive and it requires you to think in terms of relational algebra. This is awesome in a lot of ways, but as an app developer moving back and forth between treating my objects as domain objects vs storage model is a total brain melt.
<FromGitter> <jgaskins> I think Neo4j's query language Cypher is even more expressive than any Ruby or Crystal DSL I would write around it. There's a lot of great benefits to persisting the objects in a similar structure to how you're using them in the application.
<FromGitter> <tenebrousedge> @jgaskins my last project was based on neo4j, but the requirements were vague and trivial, so I didn't get very deep into it. Do you have a project you'd like to show off?
<FromGitter> <dscottboggs_gitlab> @Blacksmoke16 it was just the conversion between Base64 that was causing the trouble I think, but I've got something else to do right now, I'll let you know when I get it working
<FromGitter> <Blacksmoke16> šŸ‘
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
DTZUZO has quit [Read error: Connection reset by peer]
DTZUZO has joined #crystal-lang
tankf33der has left #crystal-lang [#crystal-lang]
<FromGitter> <dscottboggs_gitlab> @Blacksmoke16 https://carc.in/#/r/6xmv
sympatico has quit [Quit: ZNC - http://znc.in]
sz0 has quit [Quit: Connection closed for inactivity]
<FromGitter> <Blacksmoke16> hmm, gotcha
<FromGitter> <vladfaust> I need a little help. I'm writing to a socket, and server (bare socket server) `gets`. But `while temp = gets` is stuck unless the socket (not the server) is closed
<FromGitter> <vladfaust> I don't want to close the client socket, I want to reuse it instead
<FromGitter> <vladfaust> But `while temp = client.gets` just freezes
<FromGitter> <vladfaust> Well, socket's IO doesn't have end unless it's closed, I see
<FromGitter> <vladfaust> Nevermind, I've got this šŸ‘
alexherbo250 has joined #crystal-lang
alexherbo25 has quit [Ping timeout: 244 seconds]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <jwoertink> glad we could be of some help! šŸ„
laaron- has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron- has quit [Quit: ZNC 1.7.1 - https://znc.in]
alexherbo250 has quit [Ping timeout: 246 seconds]
alexherbo250 has joined #crystal-lang
<FromGitter> <mwlang> hmmm... no "let" memoizing macro for specs?
<FromGitter> <mwlang> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cdf33f19404bf2aed648380]
<FromGitter> <mwlang> tried ```getter connection : Binance::REST { Binance::REST.new }``` instead, but get this: "can't declare def dynamically"
<FromGitter> <Blacksmoke16> why not just do liek
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cdf34baad024978c6e3fe0e]
<FromGitter> <Blacksmoke16> ?
<FromGitter> <mwlang> only because I'm stuck in Ruby-land. :-D
<FromGitter> <Blacksmoke16> or just new up an instance in every block
<FromGitter> <Blacksmoke16> im assuming thats what `let` does?
<FromGitter> <mwlang> well, Let's kind of special...it memoizes, but forgets in between every "it"
<FromGitter> <mwlang> that way memoized instances don't leak across tests
<FromGitter> <Blacksmoke16> i.e. news up an obj before executing every it block
<FromGitter> <Blacksmoke16> so each it block has a new instance
<FromGitter> <mwlang> where is "like" documented?
moei has quit [Quit: Leaving...]
<FromGitter> <Blacksmoke16> Like?
<FromGitter> <mwlang> nvm, just realized I misread!
<FromGitter> <mwlang> so you're saying setting connection = Binance::REST.new will new up every "it" block with fresh instance?
<FromGitter> <mwlang> no other magic required?
<FromGitter> <dscottboggs_gitlab> no
<FromGitter> <dscottboggs_gitlab> it doesn't do that
<FromGitter> <dscottboggs_gitlab> Generally for that sort of thing, I do something like
<FromGitter> <dscottboggs_gitlab> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cdf3a93879f4478c7992d53]
<FromGitter> <dscottboggs_gitlab> I agree it would be kinda convenient if we could have a defined fixture for a `describe` block but it has not been implemented yet
<FromGitter> <dscottboggs_gitlab> Is this (https://github.com/crystal-lang/crystal/blob/639e4765f3f4137f90c5b7da24d8ccb5b0bfec35/src/gzip/reader.cr#L67) some special syntax? I'm assuming it's just short for āŽ āŽ ```begin āŽ yield reader āŽ ensure āŽ reader.close āŽ end``` āŽ āŽ but can that be used in other circumstances than a yield statement? [https://gitter.im/crystal-lang/crystal?at=5cdf3b458265145bbb2bbb0c]
<FromGitter> <mwlang> doesn't look "special" to me.
<FromGitter> <mwlang> assuming ensure can trail a statement just like ```rescue``` or ```if``` -- common in Ruby at least.
<FromGitter> <dscottboggs_gitlab> yeah I'm not a big ruby guy -- I didn't realise `rescue` or `ensure` could be used as postfixes
<FromGitter> <Blacksmoke16> @mwlang yea no sorry. i was trying to understand if that was what `let` did
return0e_ has quit [Ping timeout: 246 seconds]
<FromGitter> <Blacksmoke16> at that point why not just do `Biance::REST.new` in each it block
<FromGitter> <Blacksmoke16> no need to abstract stuff just for sake of abstracting it
return0e has joined #crystal-lang
<FromGitter> <asterite> Just define a file private method that returns the connection, and call that
<FromGitter> <Blacksmoke16> can you pass an empty tuple in a generic?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6xnv
devil_tux has joined #crystal-lang