<Andriamanitra>
i noticed "in" is a keyword in crystal.. where is it used? i tried searching but it's pretttty hard to find anything for such a commonly used word
<FromGitter>
<naqvis> Andriamanitra `in` is used in exhaustive `case`
<FromGitter>
<naqvis> `case when` requires `else` clause, so they added new keyword `in` to avoid adding `else` clause
<Andriamanitra>
thanks, i think i understand.. although it is a bit weird
<FromGitter>
<naqvis> `in` is exhaustive and it will decline to compile, if you haven't covered all branches (same behavior followed by other languages)
<FromGitter>
<naqvis> this was lately added to language
<Andriamanitra>
yeah, the word "in" just doesn't communicate the intent very clearly
<Andriamanitra>
you'd think they would've at least considered something like exhaustive_case instead
f1refly2 has joined #crystal-lang
f1refly2 is now known as f1reflyylmao
<FromGitter>
<HertzDevil> there's also `for ... in ...` but it's only available within macros
<f1reflyylmao>
Is there a shortcut to get the last element from an array? I'm searching for some fancy alias function that would wrap arr[arr.size - 1] for me
<Andriamanitra>
.last
<FromGitter>
<HertzDevil> `arr[-1]`
<kevinsjoberg>
I honestly believe my input for day 4 is broken :P
<kevinsjoberg>
I got the right answer for part 1, I correctly validate all test inputs provided for p2, but the answer I provide is not correct.
<Andriamanitra>
i was fortunate enough to not have any bugs, it would be a painful day to debug
<f1reflyylmao>
Man, I cant read. Sorry for asking.
<kevinsjoberg>
I honestly can see what I do wrong.
<Andriamanitra>
have you tried with someone else's input?
<kevinsjoberg>
Nope, I haven't
<kevinsjoberg>
Have you done yours? Care to share?
<kevinsjoberg>
Am I blind? I've started at this for some time now.
<yxhuvud>
I can recommend looking at the passports it accepts. At least one is wrong :)
<kevinsjoberg>
But that's the thing. The test cases pass for the test input. I'll just run the puzzle input through the validator.
<Andriamanitra>
maybe your regexes are matching partially?
<kevinsjoberg>
Holy shit you're right.
<kevinsjoberg>
Added \A \z and its down to 114.
<kevinsjoberg>
Such a dumb mistake.
<yxhuvud>
kevin, I didn't suggest you look at the test input, I suggested to look at the actual passports.
<kevinsjoberg>
yeah, I got it a bit late. You wanted me to run the actual passports through the validator, right?
<yxhuvud>
you can't trust that the test cases given cover all cases for your particular solution
<kevinsjoberg>
true, I tend not to, but I felt confident enough about the validator given those cases passed and the logic was fairly simple.
<kevinsjoberg>
but yeah, should probably get into the habit of playing around with the puzzle input more often.
<FromGitter>
<Daniel-Worrall> everyone gets the same input
<Andriamanitra>
no, there are definitely different inputs although i don't know how many
<FromGitter>
<Daniel-Worrall> oh, huh
<postmodern>
does anyone know of a crystal json streaming parser that can handle massive json files/streams? kind of want to write a generic json pretty printer that indents the json properly without loading it all into memory.
<kevinsjoberg>
This is what I ended up with. Not the best, but it works.
<jhass>
postmodern: stdlib JSON::PullParser is streaming and I'd say pretty performant
<jhass>
and so is JSON::Builder
<jhass>
so it should pretty much just be hooking up the two
<postmodern>
jhass, trying to grok the API. appears i call #read_next and it returns a Symbol for the token, then i have to call the appropriate method to parse that object
<postmodern>
guess that's another project for my TODO list
<FromGitter>
<kingsleyh> ah ok - the servers are the small t2.micros
<FromGitter>
<kingsleyh> ok working now that I stopped some stuff on the box
<riffraff169>
isnt t2 deprecated? i think t3 is the new one, unless not available in that region
<FromGitter>
<lodenos> Hello Crystal Community <3 β I try to doing something with the `JSON::Serializable` Iβve a spetific case I would like to do it β I would like at the moment the Serialization convert my int in string like as converter β β ```class Toto β @[JSON::Field(converter: self.test)] β getter tag : UInt16``` [https://gitter.im/crystal-lang/crystal?at=5fca48ee29463f19c672b24a]
<oprypin>
lodenos, i dont understand
<FromGitter>
<Blacksmoke16> the converter needs to be something that implements a `from_json(pull : JSON::PullParser)` method
<FromGitter>
<Blacksmoke16> either a type, or object
<FromGitter>
<lodenos> @oprypin Iβve edited
<FromGitter>
<lodenos> @Blacksmoke16 Hum Itβs this part Iβvnβt understand
<FromGitter>
<lodenos> @Dan-Do Let me test for my case
<hightower2>
Hey @Blacksmoke16 I see you've done something re. amqp-client. Do you know how to perform a basic_publish with (delivery_mode=2) to make msgs persistent? Is that the _confirm variant of the function or?
<hightower2>
hm seems I should pass props:
<FromGitter>
<ImAHopelessDev_gitlab> hai
<FromGitter>
<Blacksmoke16> hightower2 its part of the `props` argument
<FromGitter>
<Blacksmoke16> > Class variables are inherited by subclasses with this meaning: their type is the same, but each class has a different runtime value
<FromGitter>
<tenebrousedge> so if your `begin` `end` block is scoped to the method, just call it again
<hightower2>
nice one thanks @Blacksmoke16 !
<hightower2>
tenebrousedge right but wouldn't a function calling itself keep increasing the function call depth? Also I would have to repeat the arguments to the function (not a big deal, but ideally I'd find something that literally retries, instead of me calling it again))
<FromGitter>
<anapsix> I do wish there would be a way to pick master/HEAD version on play.crystal-lang.org
<FromGitter>
<tenebrousedge> hightower2 probably, yeah. If `retriable` fits better, def use that
<FromGitter>
<Blacksmoke16> its possible with snap
<FromGitter>
<Blacksmoke16> can do like `snap install crystal --edge`
<straight-shoota>
nightly docker images have also been available for years
<FromGitter>
<anapsix> point taken @straigh-shoota β is that the right repo, though? doesn't look like it has crystal 0.30+
<FromGitter>
<j8r> @kingsleyh riffraff169 is right, we use t3a at work
<FromGitter>
<j8r> they are cheaper, and have 1 core more for little instances
<straight-shoota>
pretty sure, yes
<straight-shoota>
unless jhass has another hidden repo somewhere
<straight-shoota>
the software itself even runs on 0.34.0 so it should support 0.30+
<erdnaxeli>
hi, is there something to know on a file if it is the "main" file executed? like `if __name__ == "__main__"` in python?
<FromGitter>
<Blacksmoke16> i doubt it
<FromGitter>
<Blacksmoke16> what are you trying to do?
<FromGitter>
<tenebrousedge> I think it might though
<erdnaxeli>
for the AoC I have one file per day, with some function, and then some calls to those functions. I just want those calls to not be done if I am importing the file, which IΒ do in the spec file.
<oprypin>
@erdnaxeli:cervoi.se is this a new feature coming from matrix buying gitter?
<FromGitter>
<erdnaxeli:cervoi.se> yep exactly
<oprypin>
awesome awesome
<FromGitter>
<oprypin:matrix.org> π€
<oprypin>
the bridging was very slow
<FromGitter>
<tenebrousedge> huh, right on
<oprypin>
erdnaxeli:cervoi.se, was there any other step to make this more seamless towards irc?
<Andriamanitra>
tenebrousedge: i really like your day 4 solution, using procs for the rules is so much cleaner than the monster of a case-when statement i ended up doing!
<Andriamanitra>
i also hadn't seen record with a &block before, interesting
<FromGitter>
<tenebrousedge> Andriamanitra hey thanks ^__^ I was feeling a little worried about that decision because everyone else seemed to go with a `case` or something
<FromGitter>
<Daniel-Worrall> I think the really nice thing about AoC is getting the opportunity to work on the same puzzles and then getting insight into methods and ideologies of how to code better from more experience developers, and be able to talk about it afterwards in real time
<FromGitter>
<tenebrousedge> did you post your solution earlier?
<FromGitter>
<Daniel-Worrall> Uh, I posted mine in the discord, sec
<FromGitter>
<Daniel-Worrall> Mine wasn't as neat as I'd like
<FromGitter>
<Daniel-Worrall> I also did regex when I didn't need to
<FromGitter>
<Daniel-Worrall> so slight inefficiencies
<FromGitter>
<tenebrousedge> I would just have done the `begin` block over the whole method there
<FromGitter>
<tenebrousedge> use the `def ... rescue ... end` thing
<FromGitter>
<Daniel-Worrall> hmm, maybe, I just wanted to keep it contained to just that code that I knew what I was rescuing so it was clear on the intent
<FromGitter>
<tenebrousedge> well, I split those up
<FromGitter>
<tenebrousedge> thought it made more sense to have that be an `&&` rather than one big long procedure
<FromGitter>
<Daniel-Worrall> 1 bit I was trying to do and didn't implement by the time I got the solution was short cirtcuiting failure. I had an array of the outcomes of the rules and just applied `#all?` which meant it had to evaluate them all
<FromGitter>
<Daniel-Worrall> Also, didn't know I could do `from <= number <= to`
<FromGitter>
<tenebrousedge> yes!
<FromGitter>
<tenebrousedge> it's quite handy for I think day 03 too
<FromGitter>
<Daniel-Worrall> day 2
<FromGitter>
<tenebrousedge> ah, kay
<FromGitter>
<tenebrousedge> :plus1:
<Andriamanitra>
quite a few solutions also used ranges for the same thing, don't know which is actually better
<FromGitter>
<tenebrousedge> I didn't bother with `to_i`
<FromGitter>
<Daniel-Worrall> Asterite had a Rules and iterated with `#all?` so it would only test the rules until it hit failure
<FromGitter>
<tenebrousedge> me too
<FromGitter>
<tenebrousedge> huh
<FromGitter>
<tenebrousedge> I should check his solution
<FromGitter>
<Daniel-Worrall> Yeah, I'd like to see whch is more performant
<straight-shoota>
ranges are super expressive for such things
<straight-shoota>
like value.in? 150..200
<FromGitter>
<Daniel-Worrall> cause it'll end up testing each case?
<FromGitter>
<Blacksmoke16> @straight-shoota while you're here i noticed some things you prob know about
<FromGitter>
<Blacksmoke16> er at least before i make issues/prs
<straight-shoota>
shoot =)
<FromGitter>
<Daniel-Worrall> I was looking for some sort of `#between?` method since I didn't know about `f<=x<=t`
<straight-shoota>
Blacksmoke16, I guess there are even more APIs that haven't been updated to include Path
<FromGitter>
<tenebrousedge> hmm, maybe I should go back and use string ranges
<straight-shoota>
it was already hard to convince everyone to have Path at all, so I didn't want to start spamming it everywhere. But then it got forgotten...
<FromGitter>
<Daniel-Worrall> where does the expense come in that straight-shoota means? From initalising the Range?
<straight-shoota>
Daniel-Worral expressive, not expensive
<FromGitter>
<Blacksmoke16> i think it deff makes sense when working with files
<FromGitter>
<Daniel-Worrall> AH
<FromGitter>
<Daniel-Worrall> That's a derp on me
<FromGitter>
<Blacksmoke16> like storing a path to a file, so that things could work on either linux or windows
<FromGitter>
<Blacksmoke16> lastly, also related to that preader thing, thoughts on having `bytesize` be optional?
<FromGitter>
<Blacksmoke16> i.e. "optionally only read x bytes, otherwise read rest of file from given offset"