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
<raz> blacksmoke16: fyi, just did my athena upgrade. view -> view_context, QueryParam -> RequestParam and now POST works like a champ 👍
<FromGitter> <Blacksmoke16> 👍 good to hear
<FromGitter> <mwlang> Is it possible to write shared specs that can be run in different contexts like with rspec?
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 260 seconds]
<FromGitter> <mwlang> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5fd19ca32a954a51a9c08ead]
<FromGitter> <mwlang> Looking for a solid strategy to DRY that up as I don't want double the integration test scenarios just because I have two different services. The API endpoints of each will vary some, but perhaps 90% of the APIs are the same between the two.
avane has quit [Quit: ZNC - https://znc.in]
avane has joined #crystal-lang
<FromGitter> <watzon> The built in spec runner is very simple. If you want something more like RSpec I recommend Spectator
<FromGitter> <mwlang> thanks, @watzon. I took a look, but spectator doesn't seem to support shared groups/contexts. Definitely is a lot closer to Rspec than the built-in spec runner, though.
<FromGitter> <watzon> Can you setup multiple logging backends?
<FromGitter> <watzon> Nvm, found the BroadcastBackend
<Andriamanitra> how do i collect from an iterator?
<Andriamanitra> surely there's something similar to ruby's #collect method
<Andriamanitra> err i mean ruby's #to_a, python's collect()
<FromGitter> <naqvis> you can call `to_a` terminal operator as well
<Andriamanitra> you mean .not_nil!.to_a ? :/
<FromGitter> <naqvis> ```pp (0..2).each.to_a # => [0, 1, 2]```
<FromGitter> <naqvis> `each` returns the `Iterator`
<FromGitter> <naqvis> https://crystal-lang.org/api/0.35.1/Enumerable.html#each_cons_pair(&:T,T-%3E_):Nil-instance-method
<FromGitter> <naqvis> `each_cons_pair` returns `Nil`
<Andriamanitra> so there's no way to collect stuff from it other than to explicitly append to a list inside the block?
<FromGitter> <naqvis> yeah, because it itself is a terminal operator
<FromGitter> <naqvis> it iterates over the iterator
<Andriamanitra> i see
<Andriamanitra> so i would need to define my own #map_each_cons_pair method then?
<Andriamanitra> ..i'm sure i've done something like this before in ruby but for some reason i'm having all kinds of issues today
<FromGitter> <naqvis> what are you trying to achieve?
<Andriamanitra> i'm trying to map the result of an operation between each pair in an array to another array
<Andriamanitra> or if i could call #any? on an iterator that gives me all the pairs that would be even better
<FromGitter> <naqvis> Definitely not optimized, but sth for your reference ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5fd1c8bdb6b8f41abb81c9b6]
renich has joined #crystal-lang
<Andriamanitra> i ended up side-stepping the problem by doing seq[1..].zip(seq) instead
<Andriamanitra> would be nice if each_cons could be combined with other nice things, i'm still a bit confused why it needs to be what you call "terminal operator"
<FromGitter> <HertzDevil> ```[1, 2, 3, 4, 5].each.cons(2).to_a # => [[1, 2], [2, 3], [3, 4], [4, 5]]```
<FromGitter> <HertzDevil> there's also `.each.cons_pair` actually
fifr has quit [Quit: ZNC 1.7.1 - https://znc.in]
<FromGitter> <HertzDevil> however that would break things on 0.35.1 until crystal-lang/crystal#9788
sorcus has quit [Ping timeout: 264 seconds]
<FromGitter> <naqvis> 👍
<Andriamanitra> ohhhhh i was just supposed to have . instead of _
sorcus has joined #crystal-lang
<yxhuvud> you can use each_cons(2).map {}
<yxhuvud> (I'm not very happy with part2)
<Andriamanitra> oh wait each_cons_pair is the only weird one? each_cons(2) also works just fine
<FromGitter> <HertzDevil> to be precise, when you call `.each_cons` without a block you end up calling the method from `Iterable` instead of `Enumerable`
<FromGitter> <HertzDevil> that method in turn is simply an alias of `.each.cons`
<FromGitter> <HertzDevil> otoh `Iterable` does not define the block-less `#each_cons_pair`
<Andriamanitra> is that intended? seems unnecessarily confusing
<FromGitter> <HertzDevil> there were talks to remove `Iterable` altogether because all the methods there are simply wrappers around the block-less `.each`
<FromGitter> <HertzDevil> `#each`
repo has quit [Ping timeout: 240 seconds]
repo has joined #crystal-lang
<Andriamanitra> interesting, thanks
<FromGitter> <HertzDevil> and everywhere it's used for method overloading, the same methods also take `Iterator`s
<FromGitter> <HertzDevil> and there are only two: `Iterator.chain` and `Enumerable#zip(?)`
sorcus has quit [Ping timeout: 260 seconds]
sorcus has joined #crystal-lang
<Andriamanitra> i think i'm finally finished with this painful day, although i'm not at all happy with the solution https://github.com/Andriamanitra/adventofcode2020/blob/main/day10/solution.cr
return0e[m] has quit [Quit: Idle for 30+ days]
ua_ has quit [Read error: Connection reset by peer]
postmodern has quit [Quit: Leaving]
ua_ has joined #crystal-lang
<kevinsjoberg> I found part 1 really easy, but I'm at a loss at part 2.
<kevinsjoberg> Don't have time to sit with it right now either, so there's that.
<kevinsjoberg> It's a shame when you have like 30 minutes in the morning before the kids starts terrorizing you, haha.
<Andriamanitra> yeah part2 took me over two hours..
<Andriamanitra> that's like the previous 4 days combined
<FromGitter> <asterite> Part 2 was really interesting today! https://github.com/asterite/adventofcode2020/blob/master/10/10.cr
<yxhuvud> nice!
<yxhuvud> `i + 1..` <- wait what. Does addition work on ranges? o_O
<Andriamanitra> i think we've entered the territory where i can't understand how the solutions work any more :D
<kevinsjoberg> yxhuvud: isn't addition just done first? so the range is (i+1)..
<yxhuvud> hmm, ah could be that the .. priority is lower. hmm.
<FromGitter> <asterite> and the formatter adds the spaces, so... maybe I'll remove that rule from the formatter
<yxhuvud> probably not worth the effort :)
ua_ has quit [Ping timeout: 264 seconds]
ua_ has joined #crystal-lang
<FromGitter> <KevinSjoberg> Anyone interested in reviewing https://github.com/crystal-lang-tools/sublime-crystal/pull/74 before I merge?
<FromGitter> <mwlang> Is WebMock, and specifically the `after_live_request` callback still working? I am finding that the response.body is always an empty string, yet I can see body_io has bytes. If I don't use Webmock, the body is populated.
<FromGitter> <mwlang> gist of what I'm seeing and the code: https://gist.github.com/mwlang/d9dd5ebda76565699e633ca8ca261909
<FromGitter> <mwlang> @KevinSjoberg that one line of regex's is rather long, esp. relative to the others below it. Perhaps consider treating module, class, and methods on separate lines. A little less DRY, but more readable/maintainable over the long-run.
<FromGitter> <KevinSjoberg> @mwlang fair point. I'll update it. 👍
<FromGitter> <Blacksmoke16> @mwlang https://athena-framework.github.io/spec/Athena/Spec/TestCase.html is another option
<FromGitter> <Blacksmoke16> bit diff style but is essentially syntax sugar to `Spec` module
mistergibson has joined #crystal-lang
<FromGitter> <asterite> WebMock should be part of the std so it doesn't fall out of sync
<FromGitter> <asterite> Same for timecop
skrzyp has joined #crystal-lang
<FromGitter> <Blacksmoke16> a simpler thing related to time could be like `Time.set_test_now 2020, 12, 8, ...`
<FromGitter> <Blacksmoke16> just make `Time.utc` and `Time.local` return that static time
<FromGitter> <HertzDevil> should we allow setters as macro names?
<FromGitter> <HertzDevil> right now `macro foo=; end` isn't parsed properly but `macro []=(k, v); end` actually works
<FromGitter> <HertzDevil> for context this is about crystal-lang/crystal#10022
duane has quit [Ping timeout: 260 seconds]
<FromGitter> <asterite> It should be disallowed but it doesn't matter much
<FromGitter> <HertzDevil> fine by me
<FromGitter> <HertzDevil> taking this a step further i think we don't need any of the operator macros either, except `[]`
<FromGitter> <HertzDevil> did a simple regex check and `[]` is the only one crystal itself uses
<FromGitter> <anapsix> greetings! ⏎ I was making a YAML parser for `Time::Span`, and wondering is there is a better way of turning `Time::Span` into a string than checking for increasingly smaller time units, and using them as a base measurement for string `{amount}.{measurement}` ⏎ https://play.crystal-lang.org/#/r/a3dm
<FromGitter> <Blacksmoke16> could you just turn it into an object with start and end times?
<FromGitter> <anapsix> it's not as much of problem of converting from yaml, as it is to yaml
<FromGitter> <anapsix> unless I misunderstand what you mean
<FromGitter> <Blacksmoke16> nvm, span doesnt really have a specific start/end datetime
<FromGitter> <Blacksmoke16> couldnt you just store the total ms or something?
<FromGitter> <anapsix> yeah.. settling on a base measurement would help
<FromGitter> <Blacksmoke16> mhm
<FromGitter> <anapsix> seconds or milliseconds seems reasonble
<FromGitter> <Blacksmoke16> indeed
renich has quit [Ping timeout: 256 seconds]
ua_ has quit [Quit: Leaving]
ua has joined #crystal-lang
<FromGitter> <anapsix> ended up with this ⏎ https://play.crystal-lang.org/#/r/a3ef
<FromGitter> <Blacksmoke16> mk
<FromGitter> <Blacksmoke16> any reason for all the complexity? versus just like having the interval be a static value like unix time?
f1reflyylmao is now known as f1refly
<FromGitter> <erdnaxeli:cervoi.se> Hi ! I got this code that seems to compile in carc, but does not on my machine: https://carc.in/#/r/a3fb
<FromGitter> <erdnaxeli:cervoi.se> I got ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5fd2735c91e8cb3e8cf2a2f9]
<FromGitter> <Blacksmoke16> are you sure its the same, i.e. if code isnt used it isnt included in the binary
<FromGitter> <erdnaxeli:cervoi.se> yeah I am quite sure. I copied this code in a file `t.cr` and ran `crystal run t.cr`.
<FromGitter> <erdnaxeli:cervoi.se> this is with `crystal play`
<kevinsjoberg> I'm really stuck at p2 for day 10. I just feel that there's a clever way of solving it and I'm not seeing it. I guess my lack of a formal degree in cs and nonexistent math skills (was bullied through most of school) is really shining through.
<FromGitter> <tenebrousedge> eh. I'm a couple of days behind at this point. I wouldn't feel too bad
<FromGitter> <tenebrousedge> the point is just to be coding, to take on the challenge
<kevinsjoberg> I've been fiddling on my own to reason about the problem. But I have no-one to ask if my logic holds. Seem correct for the sample input. https://gist.github.com/KevinSjoberg/4b54cc6ebf6e9d43c901333f56f60075
<kevinsjoberg> But that could very well just be a coincidence.
<kevinsjoberg> @tenebrousedge yeah, you're right. I guess I should just try to have fun instead of feeling stressed over not "getting it".
<FromGitter> <tenebrousedge> :plus1:
<FromGitter> <tenebrousedge> I didn't code at all yesterday, and I'm still not happy with my solution to 8.2 yet, so I'm debugging that
<FromGitter> <KevinSjoberg> I see. I guess Imposter Syndrome was just hitting extra hard today. :slight_smile:
<FromGitter> <tenebrousedge> I did a five mile hill run yesterday and I refuse to feel bad about not coding 😆
<Andriamanitra> kevinsjoberg: how did you come up with that logic?
<FromGitter> <KevinSjoberg> Sounds wonderful!
sagax has joined #crystal-lang
<kevinsjoberg> Andriamanitra: I don't know really, just throwing shit at the wall and see if it sticks?
<Andriamanitra> oh :D in that case i doubt it works, i don't see why it would (or how you would get an answer in the trillions just by doing addition)
<kevinsjoberg> I don't think it does. :P
<kevinsjoberg> I'm just tired, I probably need to take a break. Long day at work, and just put the kids to bed.
<yxhuvud> andrian: huh? I certainly didn't use anything else than addition.
<Andriamanitra> yxhuvud: like i said earlier, we've gone beyond the point where i understand other people's solutions :p
<kevinsjoberg> Well, I guess I'll give up for now. Obviously not going to work just sitting here banging my head.
<FromGitter> <tenebrousedge> sometimes I do my best coding in the shower
<yxhuvud> sleeping on it can be good too.
<FromGitter> <tenebrousedge> yus
<FromGitter> <Blacksmoke16> @erdnaxeli:cervoi.se prob just a product of how the playground isnt 100% the same
<FromGitter> <erdnaxeli:cervoi.se> @Blacksmoke16 My problem is actually that it does not run on computer, and I don't understand why
<FromGitter> <watzon> Hmmmm
<FromGitter> <Blacksmoke16> i noticed that oo!
<FromGitter> <Blacksmoke16> too!
<FromGitter> <watzon> carc.in isn't giving me any output
<FromGitter> <Blacksmoke16> i think its 🔥
<FromGitter> <watzon> Seems to be
<FromGitter> <watzon> play.crystal-lang.org is too
<FromGitter> <Blacksmoke16> @erdnaxeli:cervoi.se might be a bug, as you're deff setting it in all children
<FromGitter> <Blacksmoke16> \cc @asterite
<FromGitter> <KevinSjoberg> Well at least I published a new Sublime Crystal release. 🎉
<FromGitter> <erdnaxeli:cervoi.se> how can I wait on many channels?
<FromGitter> <watzon> Has ST improved at all recently?
<FromGitter> <erdnaxeli:cervoi.se> I have an array of channels, and I want to known which one has something to read
<FromGitter> <erdnaxeli:cervoi.se> I tried `Channel.select` but I got `Error: no overload matches 'Channel(Nil).select' with type Array(Channel(Nil)`
<FromGitter> <watzon> Idk if you can easily. Go has the concept of a WaitGroup, but Crystal doesn't.
<FromGitter> <Blacksmoke16> youd want to use a channel
<FromGitter> <watzon> I know people have tried to come up with WaitGroup implementations for Crystal though
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5fd282ab5a63c56105214936]
<FromGitter> <erdnaxeli:cervoi.se> @watzon: it seems nice, thanks
<FromGitter> <Blacksmoke16> ofc where you're spawning more than one
<FromGitter> <erdnaxeli:cervoi.se> @Blacksmoke16: I have an array of channels, and I want to to a `select` over all of them.
<FromGitter> <erdnaxeli:cervoi.se> something like this: https://carc.in/#/r/a3g6 (actually it does not compile)
<FromGitter> <erdnaxeli:cervoi.se> ok I found it: `Channel.select` accepts `channel.receive_select_action`
<kevinsjoberg> @watzon what do you mean? I’m using ST 4, better than ever. 👍
<FromGitter> <watzon> Where can you get ST4? It's still at v3 on their site
<FromGitter> <watzon> Ahh you need a license and access to the Discord. I see.
<kevinsjoberg> Yep. Currently license and Discord only.
<kevinsjoberg> But it’s really nice. Faster than ever, great LSP support, and a lot of other niceties.
<FromGitter> <watzon> How different is it from ST3? Does it actually come close to approaching the feature set of VS Code?
<kevinsjoberg> Depends on what you’re after. I never liked VSCode. It’s not an editor anymore and it’s still slow. Sublime is the opposite.
<kevinsjoberg> But are you after anything specific?
<Andriamanitra> built-in extension browser, git integration?
<FromGitter> <watzon> Mostly plugin support and a good UI. One thing I've always hated about ST was the UI.
<FromGitter> <watzon> Lack of good plugins ever since VS Code entered the scene has been a problem too
<Andriamanitra> i like ST ui for the most part, it's just that certain things (like managing extensions) are very cumbersome to do
mistergibson has quit [Quit: Leaving]
<FromGitter> <erdnaxeli:cervoi.se> how can I append something to a file ? `File.write("file", "some content", "a")` truncates the file first
<FromGitter> <tenebrousedge> huh that's odd
<FromGitter> <tenebrousedge> did you try `File.open(name, 'a') do |f|` ?
<FromGitter> <Blacksmoke16> `File.write("file", "some content", mode: "a")`
<FromGitter> <Blacksmoke16> third arg is file permissions
<FromGitter> <erdnaxeli:cervoi.se> ok so it works with `write("file", "some content", mode: "a"`, but not with `write("file", "some content", "a")`
<FromGitter> <erdnaxeli:cervoi.se> weird
<FromGitter> <Blacksmoke16> right
<FromGitter> <Blacksmoke16> mode isnt the third arg
<FromGitter> <erdnaxeli:cervoi.se> aaaah you are right
<FromGitter> <erdnaxeli:cervoi.se> thanks
Nekka has quit [Ping timeout: 265 seconds]
Nekka has joined #crystal-lang
<FromGitter> <anthonyshull> is there a naming convention for properties vs methods?
<FromGitter> <anthonyshull> camel case, snake case, etc.
<FromGitter> <anthonyshull> ok, awesome. so properties should be underscore case.
<FromGitter> <Blacksmoke16> yes
DeBot has quit [Quit: Crystal IRC]
asterite has quit [Quit: Bye]
straight-shoota has quit [Quit: ZNC 1.7.5 - https://znc.in]
jhass has quit [Quit: Bye]
DeBot has joined #crystal-lang
asterite has joined #crystal-lang
straight-shoota has joined #crystal-lang
jhass has joined #crystal-lang
DeBot has quit [Quit: Crystal IRC]
straight-shoota has quit [Client Quit]
asterite has quit [Client Quit]
jhass has quit [Client Quit]
DeBot has joined #crystal-lang
asterite has joined #crystal-lang
straight-shoota has joined #crystal-lang
jhass has joined #crystal-lang
<FromGitter> <j8r> first screens of my game, still WIP: https://imgur.com/a/tC2ybtr
<FromGitter> <j8r> Little image of my DE and tabs at the end, nothing private :)
<FromGitter> <watzon> Giving me AoE vibes so far
<FromGitter> <watzon> Or StarCraft
<FromGitter> <j8r> yes, that's will be a strategy game
<FromGitter> <watzon> Awesome
<FromGitter> <j8r> But it aims to be simpler, and more strategy oriented
<FromGitter> <j8r> No tech tree, so no "the one fastest to reach the most optimized techs wins"
<FromGitter> <j8r> only units vs units, pure tactics :)
<FromGitter> <j8r> of course, backend in Crystal :)
<FromGitter> <watzon> Online multiplayer?
<FromGitter> <j8r> yep!
<FromGitter> <Daniel-Worrall> What's the frontend in?
<FromGitter> <watzon> Cool! can't wait to see it
<FromGitter> <j8r> JavaScript
<FromGitter> <Daniel-Worrall> ah, browser?
<FromGitter> <j8r> and HTML/DOM used, no canvas
<FromGitter> <j8r> It has a huge advantage of portability
<FromGitter> <j8r> and is plenty performant enough for such game
<FromGitter> <j8r> When closed-alpha ready, for those interested, I'll invite them to test and give feedbacks (I'll submit a Forum post). ⏎ Expect, maybe 1-3 months (I prefer to be large)
<FromGitter> <j8r> @watzon thanks :D
<hightower4> Awesome j8r !
<FromGitter> <j8r> thx!
<hightower4> @bew what was your reason for implementing terminfo parsing lib manually after you already created bindings for unibilium ?
<FromGitter> <Daniel-Worrall> What's the syntax for the 1 liner using the yield as an argument? ⏎ Equiv of ⏎ ⏎ ```obj.each do |i| ⏎ method(i) ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5fd2b61482222960e4da3b89]
<FromGitter> <Blacksmoke16> obj.each &->method (String)
<FromGitter> <Daniel-Worrall> Oh, it was in the block forwarding section
<FromGitter> <Blacksmoke16> Or what you're doing
<FromGitter> <Daniel-Worrall> ty smokey