jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | 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
deavmi has quit [Ping timeout: 264 seconds]
deavmi has joined #crystal-lang
deavmi has quit [Quit: No Ping reply in 180 seconds.]
deavmi has joined #crystal-lang
rocx has joined #crystal-lang
oddp has quit [Ping timeout: 264 seconds]
deavmi has quit [Ping timeout: 246 seconds]
deavmi has joined #crystal-lang
deavmi has quit [Quit: No Ping reply in 180 seconds.]
deavmi_ has joined #crystal-lang
deavmi_ has quit [*.net *.split]
ua has quit [*.net *.split]
HumanG33k has quit [*.net *.split]
Elouin has quit [*.net *.split]
sagax has quit [*.net *.split]
_whitelogger has joined #crystal-lang
oddp has joined #crystal-lang
_whitelogger has joined #crystal-lang
<yxhuvud> A quite common pattern is to create a struct with a pointer (and potentially more stuff)
f1reflyylmao has quit [Quit: bye fags]
f1refly has joined #crystal-lang
twosecslater has quit [Remote host closed the connection]
twosecslater has joined #crystal-lang
HumanG33k has quit [Ping timeout: 240 seconds]
HumanG33k has joined #crystal-lang
f1refly has quit [Ping timeout: 260 seconds]
f1refly has joined #crystal-lang
<FromGitter> <j8r> Strange, I find the API quite inconsistent here: ⏎ ⏎ ```Random.new.random_bytes ⏎ # But ⏎ Random::Secure.random_bytes``` [https://gitter.im/crystal-lang/crystal?at=5f1c6dbbd50f2b289a95429d]
<oprypin> j8r, do you want to see a pointless `.new` there returning you an object with no members or something
<FromGitter> <throwaway4rust> What do you guys think of Nim?
<FromGitter> <j8r> The API docs does not help: https://crystal-lang.org/api/master/Random/Secure.html
<FromGitter> <j8r> the method added with `extend Random` does not appear
<oprypin> yea thats on the docs
<oprypin> generator, specficially
<oprypin> j8r, u can do a funny monkeypatch too; `module Random::Secure; def self.new; return self; end; end`
<FromGitter> <j8r> `abstract`works when `extend`?
<oprypin> j8r, yea
<FromGitter> <j8r> Ho just tested, did not know
<oprypin> this is like the one time you'll see `extend` being used properly
<FromGitter> <j8r> as a work around not to be able to have `abstract self.next_u`
<oprypin> j8r, that's an incorrect assessment
<FromGitter> <j8r> `extend slef` + `def next_u` are used
<FromGitter> <j8r> maybe not used on purpose
<oprypin> i dont understand what you mean..
<FromGitter> <j8r> So, what would be the proper way is to have an abstract class method
<oprypin> oh maybe i do, i dont know
<FromGitter> <j8r> because in fact this is `self.next_u`, with the `extend self`
<FromGitter> <j8r> the API docs are very bad for https://crystal-lang.org/api/master/Random/Secure.html :(
<FromGitter> <j8r> no methods shown, plus `next_u` and `random_bytes` shown as instance methods instead of class methods
<oprypin> j8r, no it works https://carc.in/#/r/9gd3
<FromGitter> <j8r> of course, not my point, what do you want to show me?
<oprypin> >> as a work around not to be able to have `abstract self.next_u`
<DeBot> oprypin: Error: unexpected token: a - https://carc.in/#/r/9gd4
<oprypin> you dont need such a workaround, dont need `extend self`
<FromGitter> <j8r> meh, that's strange? confused
<FromGitter> <j8r> you're not implementing the instance method `def next_u` here :/
<FromGitter> <j8r> and it works by implementing the class method instead?
<FromGitter> <j8r> ha, ok understood how this works
<FromGitter> <j8r> if `include` is used, one has to implement`def next_u`. If `extend` is used, one has to implement`def self.next_u`...
duane has quit [Ping timeout: 258 seconds]
duane has joined #crystal-lang
<oprypin> j8r, did you see the most fun part - Random::Secure can be passed when an instance of Random is expected
<oprypin> >> [1,2,5,10].shuffle!(Random::Secure)
<DeBot> oprypin: # => [5, 2, 1, 10] - https://carc.in/#/r/9gd5
DTZUZU_ has joined #crystal-lang
DTZUZU has quit [Ping timeout: 240 seconds]
DTZUZU has joined #crystal-lang
DTZUZU_ has quit [Ping timeout: 256 seconds]
<FromGitter> <j8r> !
<FromGitter> <j8r> anything having `.rand` will work. Passing either `Random` or `Random.new` work (!)
<oprypin> yea i suppose.. they didnt specify the type as : Random
<FromGitter> <j8r> There is no `Random::Secure.new`, quite logicial
<FromGitter> <j8r> *logical
<FromGitter> <j8r> Maybe `Random | Random.class`... lol
<oprypin> j8r, no u dont understand
<oprypin> >> Random::Secure.is_a? Random
<DeBot> oprypin: # => true - https://carc.in/#/r/9gdi
<FromGitter> <j8r> But: https://carc.in/#/r/9gdj
<FromGitter> <j8r> one can't pass `shuffle!(Random)` then
duane has quit [Read error: Connection reset by peer]
<oprypin> yes, that is correct and expected
duane has joined #crystal-lang
<FromGitter> <j8r> Just saying this is not very intuitive as an user
<FromGitter> <j8r> `shuffle!(Random)` won't work but `shuffle!(Secure::Random)` will
<FromGitter> <j8r> (if a type restriction is defined)
duane has quit [Ping timeout: 240 seconds]
duane has joined #crystal-lang
<FromGitter> <mixflame> how do I tell `to_s` I want utf8?
<oprypin> mixflame, you don't? to_s returns text, while utf8 is not text, it's a sequence of bytes
<FromGitter> <mixflame> oh
andremedeiros has quit [Quit: ZNC 1.8.1 - https://znc.in]
andremedeiros has joined #crystal-lang
HumanG33k has quit [Ping timeout: 240 seconds]
<FromGitter> <sirikon> Hi there 👋 , ⏎ ⏎ Is there any built-in mechanism in Crystal for a cancellable subscriber? ⏎ ⏎ I have a process running generating output, and also have a WebSockets connection. Want to send an stream of the process output thru the websockets connection, to the clients, but clients could disconnect, so the subscription should be cancellable. [https://gitter.im/
<FromGitter> ... crystal-lang/crystal?at=5f1ca4f7fe6ecd288873615b]
<FromGitter> <sirikon> Could do it myself I guess, but if there's something already done in the stdlib, would prefer it :)
Munto has quit [Ping timeout: 246 seconds]
<FromGitter> <j8r> If the client disconnect, then it would be an IO Error
<FromGitter> <j8r> There is a `WebSocket::Handler#on_close` handler
<FromGitter> <sirikon> Yea, I know that one, but if the mechanism is for example a block or a channel, I would then need to clean up after disconnection
<FromGitter> <j8r> Actually https://crystal-lang.org/api/master/HTTP/WebSocket.html#on_close(&on_close:CloseCode,String-%3E)-instance-method
<FromGitter> <sirikon> My question was if there's something that does that cleanup (cancellation) for me
<FromGitter> <sirikon> maybe didn't explain myself
<FromGitter> <j8r> Cleanup what?
<FromGitter> <j8r> Your case is if the client closes the connection?
<FromGitter> <sirikon> I'm playing right now, will try to explain later, so I can do it better and don't waste your time :)
ryanprior has joined #crystal-lang
<FromGitter> <j8r> So, each websocket connection spawn a fiber
<FromGitter> <j8r> There is an infinite loop inside a fiber. When the connection is closed or any eror, `@on_close` is called, loop is broken and then fiber can finish
<FromGitter> <mixflame> `sodium.cr` doesn't seem to work with `sodium-swift`
<FromGitter> <mixflame> I can't see what I'm doing wrong https://github.com/mixflame/GlobalChat2/pull/101
<FromGitter> <imeraj> Hello, what's the correct way to keep receiving values from an unbuffered channel until it's closed?
sagax has quit [Remote host closed the connection]
<FromGitter> <sirikon> @j8r An example: ⏎ ⏎ I have two fibers: ⏎ ⏎ 1) One fiber is a WebSockets connection. ... [https://gitter.im/crystal-lang/crystal?at=5f1cb457cd7bed0e378ee4e5]
<FromGitter> <sirikon> An `Observable` *
_whitelogger has joined #crystal-lang
<FromGitter> <mixflame> how do I make a crystal utf8 string from a Bytes object? looks like I got it to decrypt
oddp has quit [Ping timeout: 240 seconds]
<FromGitter> <asterite> String.new(bytes)
<FromGitter> <asterite> check the String docs