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
ur5us has quit [Ping timeout: 240 seconds]
postmodern has joined #crystal-lang
ur5us has joined #crystal-lang
<postmodern> what is the convention for targets in shards? is there a directory they are usually stored in to separate them from regular code?
<FromGitter> <Blacksmoke16> i just keep them in src
<postmodern> so i take it crystal doesn't raise a SystemExit exception when you call exit()?
<FromGitter> <Blacksmoke16> no, why?
<postmodern> porting some ruby code which catches exit() in a context and safely returns the status code. I just defined my own SystemExit exception.
<FromGitter> <Blacksmoke16> why not just do `exit status_code`
<postmodern> because that would exit the process. i want to catch it for testing purposes
<postmodern> er i should probably trap the exit signal instead
<FromGitter> <Blacksmoke16> ohh
richbridger has joined #crystal-lang
aquijoule_ has quit [Read error: Connection reset by peer]
<postmodern> another awesome thing about crystal, is it correctly exits with 130 on SIGINT, and handles Errno::EPIPE gracefully when stdout is closed prematurely. So I can delete that ruby code that rescues Interrupt and Errno::EPIPE
<FromGitter> <Blacksmoke16> 👍
notzmv has quit [Ping timeout: 256 seconds]
ur5us has quit [Remote host closed the connection]
ur5us has joined #crystal-lang
<postmodern> since crystal doesn't have documentation @tags, how do people document individual arguments of a method?
<FromGitter> <Blacksmoke16> in regard to what? Their type?
<FromGitter> <Blacksmoke16> or extra textual information?
notzmv has joined #crystal-lang
<postmodern> Blacksmoke16, additional meaning or purpose of the argument beyond it's name
<FromGitter> <Blacksmoke16> Just within doc comments of that method
<FromGitter> <Blacksmoke16> the name + type of it makes it fairly clear as well, which is super helpful
<postmodern> Blacksmoke16, but if you want to describe some deeper purpose for the argument or how it influences a method/class, what kind of markdown formatting would you use to annotate the arguments?
<FromGitter> <Blacksmoke16> there isnt a way to annotate the argument further. just would need to cover it in some way via doc comments on the method itself
<postmodern> is there an equivalent to ruby's module_function ?
<FromGitter> <Blacksmoke16> just define a class method in the module
raz has quit [Ping timeout: 272 seconds]
elf_fortrez has joined #crystal-lang
raz has joined #crystal-lang
raz has quit [Changing host]
raz has joined #crystal-lang
<postmodern> just noticed that String lacks in-place modification methods
<FromGitter> <Blacksmoke16> strings are immutable
<FromGitter> <Blacksmoke16> hence when you mutate it, it returns a new one
<postmodern> also surprised there's no String#tr(Char,Char) overload
<FromGitter> <Blacksmoke16> just use gsub at that point
<postmodern> what's the equivalent of Regexp.last_match(i) ?
<FromGitter> <Blacksmoke16> `"str".scan(...)[-1]`?
<FromGitter> <Blacksmoke16> or use `#match` with a regex that only matches the last one
<postmodern> crystal docs are not clear what String#gsub(Regexp, &block) yields
<postmodern> also how do you I specify in a type signature `Hash(String, String?) | ENV`, so a variable could be assigned a literal Hash, or the ENV module
<FromGitter> <Blacksmoke16> looks like it yeilds the matched string an a `Regex::MatchData`
<FromGitter> <Blacksmoke16> could prob do like `Enumerable({String, String?})` given ENV includes it
<FromGitter> <Blacksmoke16> but `ENV` isnt a type, so dont really think it would do what you think
<postmodern> ah ha
jhass[m] has quit [Read error: Connection reset by peer]
fifr[m] has quit [Write error: Broken pipe]
jhass[m] has joined #crystal-lang
<postmodern> Blacksmoke16, I'm guessing ENV.class is not what i want
fifr[m] has joined #crystal-lang
elf_fortrez has quit [Ping timeout: 246 seconds]
<postmodern> is there a module or some way of saying "anything that acts like a Hash"
<postmodern> also does crystal seriously not have a StringIO class?
<postmodern> er wait that might be IO::Memory
<FromGitter> <Blacksmoke16> mm dont think so. What are you wanting to do with it?
<FromGitter> <Blacksmoke16> `Enumerable({String, String})` is prob something like what you'd want
<FromGitter> <Blacksmoke16> there's also `String.build`
<postmodern> but will that ensure the given type has a #[](String) : String method?
<FromGitter> <Blacksmoke16> it would ensure key/value are both strings, at least when using the methods from that module
jhass[m] has quit [Quit: node-irc says goodbye]
fifr[m] has quit [Quit: node-irc says goodbye]
<postmodern> would you be open to me submitting an issue about adding a HashLike (or similarly named) module or abstract class?
ur5us has quit [Ping timeout: 240 seconds]
ur5us has joined #crystal-lang
<postmodern> in a module, how would you check if the super was defined before calling `super` in a method?
<postmodern> in ruby that would be `super if defined?(super)`
<postmodern> i suspect there must be a macro for checking if a method is defined in the inheritence hierarchy?
<FromGitter> <Blacksmoke16> idt you can without some macro magic
<FromGitter> <Blacksmoke16> and i doubt that'd idea would fly
<postmodern> can you define class variables in modules?
<FromGitter> <Blacksmoke16> yes
<postmodern> such that when the module is extended into a class, it's class variables are defined in the class not the module
<FromGitter> <Blacksmoke16> mm would have to test it
<FromGitter> <Blacksmoke16> otherwise could maybe make use of like `macro extended`
<postmodern> would i have to define the the class variable type inside of a macro extended ?
<postmodern> yeah
<postmodern> ah that works, now i have another error from the specs
<postmodern> is there a constant for the new-line character/string? "\n" on *nix "\r\n" on windows?
<FromGitter> <Blacksmoke16> dont think so
m4xm4n has quit [Quit: Connection closed for inactivity]
lucf117 has joined #crystal-lang
lucf117 has quit [Remote host closed the connection]
ur5us has quit [Ping timeout: 240 seconds]
jhass[m] has joined #crystal-lang
fifr[m] has joined #crystal-lang
jhass[m] has quit [Quit: Client limit exceeded: 20000]
fifr[m] has quit [Quit: Client limit exceeded: 20000]
<yxhuvud> That'd be nice to have though.
jhass[m] has joined #crystal-lang
<yxhuvud> might be a mess though. There there still other systems that use "\n\r" ?
fifr[m] has joined #crystal-lang
jhass[m] has quit [Quit: Client limit exceeded: 20000]
fifr[m] has quit [Quit: Client limit exceeded: 20000]
jhass[m] has joined #crystal-lang
ur5us has joined #crystal-lang
ur5us has quit [Client Quit]
fifr[m] has joined #crystal-lang
fifr[m] has quit [Read error: Connection reset by peer]
jhass[m] has quit [Remote host closed the connection]
jhass[m] has joined #crystal-lang
fifr[m] has joined #crystal-lang
kevinsjoberg has joined #crystal-lang
<kevinsjoberg> didn't realize Freenode went ape-shit crazy and banned anyone using IRCCloud. Thank god we moved to Libera.
<jhass[m]> it's worse, they deleted their entire channel and userdb. It's a new network squatting the old name
<FromGitter> <confact> What makes `HTTP::Client.get(url).body_io` not work when `HTTP::Client.get(url).body` works? I want to reduce memory somehow, trying to download big files ^^
<jhass[m]> there's an issue around this somewhere, the interface is just a bit shitty. You want to use the block variant to access body_io, `HTTP::Client.get(url) { |response| File.open("dest") {|f| IO.copy(response.body_io, f) } }`
<FromGitter> <confact> Ah, thanks. Will test it.
<FromGitter> <confact> Yea, reduced the memory by 60% with that line of code, thanks @jhass[m].
<FromGitter> <szabgab> What is the name of the syntax when the condition comes after the statement (e.g. break if x > 3) in Perl this is called statement modifier, but I don't know how it is called in Crystal
elf_fortrez has joined #crystal-lang
<FromGitter> <szabgab> Thanks
elf_fortrez has quit [Quit: Client closed]
<mps> is http gracefull shutdown solved (we talked here about it two years ago, iirc)
<mps> (would be nice to remove 'reference' counting from my http servers)
<straight-shoota> Not sure what was the status back then, but should be mostly solved
<straight-shoota> When you close an HTTP::Server, it shuts down the accept sockets and no new clients will be received. But existing connections continue to be worked.
<mps> straight-shoota: ah, thanks. will test it again
<mps> I missed to read that in changes
<mps> huh, it still doesn't work
<mps> here is my test code https://tpaste.us/xnWw
<FromGitter> <didactic-drunk> I think the issue is not with the accept socket but lack of tracking already accepted sockets
<mps> iiuc the problem is in server.closed?
<mps> uh, no
<mps> I had link how to do this in golang but lost this link
<FromGitter> <didactic-drunk> `close`. closes the listening sockets. The main fiber waits for all listening sockets to close then exits. It doesn't wait for fibers handling client connections
<FromGitter> <didactic-drunk> So it's "half" graceful
<mps> maybe I need to add Fiber.yield
<mps> hm no, Fiber.yield didn't helped
<mps> have to dig old example on archive disk
<mps> but also have to finish irssi rewrite rules for this channel
<mps> perl greedy matches make me ... uff
<FromGitter> <didactic-drunk> Huh, I thought it waited for listening socket to close. Guess not. Nm.
<mps> yes, it should close listening socket but not active ones
deavmi_ has quit [Quit: Eish! Load shedding.]
<FromGitter> <didactic-drunk> @mps could you test #10884 and see if it fixes your problem?
<FromGitter> <franciscoadasme> hey everyone, is there a way to declare a subtype of a typevar (`T::U`) in a type restriction?, something like this: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60df498f368d0e1d9a3b5789]
<FromGitter> <franciscoadasme> hey everyone, is there a way to access a subtype of a typevar (`T::U`) to use it in a type restriction?, something like this: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60df49af65513b4d91440dd0]
<FromGitter> <Blacksmoke16> `include A(Foo::Bar)`
<FromGitter> <Blacksmoke16> and just use `T`
<mps> didactic-drunk: I have to rebuild crystal for this, iiuc
<FromGitter> <didactic-drunk> Possibly. You could possibly use an existing 1.0.0 build
<mps> I don't keep it around because my arm64 machines are too slow to build crystal
<FromGitter> <franciscoadasme> @Blacksmoke16 This was a simplified example, the module includes other methods that work on `T`, so I cannot simply use `Foo::Bar`
<FromGitter> <Blacksmoke16> `include A(Foo, Foo::Bar)`?
<mps> didactic-drunk: btw, I maintain crystal in last 2 years for alpine linux
<mps> for any change I have to use alpine builders and to push changes to distro
<mps> didactic-drunk: anyway I will try this patch on my local box on weekend, thank you for it
<FromGitter> <didactic-drunk> You can probably use an existing compiled 1.0.0 crystal binary with the std lib source from my branch (or just copy `http/server.cr`)
<mps> ah, lets see
<mps> didactic-drunk: In /usr/lib/crystal/core/http/server.cr:505:9
<mps> 505 | sleep timeout
<mps> Error: no overload matches 'sleep' with type Nil
<mps> but looking into patch, this is some kind of reference counting also?
<FromGitter> <didactic-drunk> Did you use `close` with or without a timeout?
<mps> without timeout, I want to close listening socket imediately
<FromGitter> <didactic-drunk> Try `close timeout: 0`
<FromGitter> <didactic-drunk> Um. Listening sockets are closed immediately regardless of timeout. Timeout is the wait time for already accepted client connections
<mps> yes, patch didn't helped
<FromGitter> <didactic-drunk> Try `timeout: 80`
<mps> will this close listening socket imediately?
deavmi has joined #crystal-lang
<mps> even with 'timeout: 80' doesn't work
<FromGitter> <didactic-drunk> It should
<mps> dies immediately
<FromGitter> <didactic-drunk> Do you have a client connection open before ctrl+c?
<mps> yes
<FromGitter> <didactic-drunk> Works on my end
<FromGitter> <didactic-drunk> With your test code
<mps> hm
<mps> ok, thanks
<FromGitter> <franciscoadasme> @Blacksmoke16 ok, thanks
<mps> I will try to build crystal with your patch on weekend and test again
<FromGitter> <didactic-drunk> Can you test on non-arm?
<mps> I can, but maybe next week (ditched x86 few years ago)
<mps> hmm, maybe I can 'usurp' my alpine developers lxc
<mps> but not now, it is to busy by building a lot of pkgs now
<FromGitter> <didactic-drunk> Nm. It's possible it needs crystal master although I don't see why. I hope it's not an arm thing
<mps> last time I tried it was same on arm and x86
notzmv has quit [Ping timeout: 252 seconds]
notzmv has joined #crystal-lang
notzmv has quit [Ping timeout: 240 seconds]
deavmi_ has joined #crystal-lang
deavmi has quit [Ping timeout: 256 seconds]
notzmv has joined #crystal-lang