<FromGitter>
<j8r> how can I get `require "uri"; puts URI.new(host: "[::1]", port: 8000)` return `[::1]:8000` instead of `//[::1]:8000`?
<FromGitter>
<j8r> without `lchop`
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
dannyAAM has joined #crystal-lang
<FromGitter>
<0x2C6> how can I change encoding? I know crystal uses utf8 by default but when I try to render a letter as a json it returns weird characters on the browser(Safari) How can I change this encoding?
<FromGitter>
<bew> @straight-shoota Wait what? How can #7377 fix #7687 ? Since he's running on WSL, the stdlib for win32 shouldn't be used (and #7377 shouldn't impact the results).. Or am I looking it wrong?
<Jenz>
These new "begin-less and end-less ranges" are amazing!
dannyAAM has joined #crystal-lang
<FromGitter>
<tenebrousedge> how so?
<Jenz>
Uh, well, I just love em! :D
<FromGitter>
<tenebrousedge> how have you used them?
<Jenz>
I haven't, but I've used very similar constructs in other languages (like julia)
<Jenz>
And I bet I'll use them from now on, I've wanted to have a go at implementing a mathematical shard, with multidimensional arrays like in julia numpy and similiar, which I'm sure will be a huge failure
* Jenz
:D
<z64>
hm, am i missing something with the new deprecation system? if i have a file with `Time.utc_now`, should it emit a warning when built with `--warnings all`?
<Jenz>
No I don't think so, isn't it Time.new that is deprecated?
<FromGitter>
<kinxer> @z64 I think it should emit a warning, yes. Is it not?
<Jenz>
kinxer, you can just do arr.each(3..) { ... }
<Jenz>
Um wait
<z64>
i just did `echo 'Time.utc_now' > test.cr` and `crystal build --warnings all test.cr` and nothing was shown
<Jenz>
I mean ofc `arr[3..].each { ... }` haha
<Jenz>
And @tenebrousedge, thanks for being an exercism mentor! :) It's great
<z64>
yeah end-less ranges are nice for that. i never liked `a[3..-1]`
<FromGitter>
<kinxer> @Jenz Right you are. Even better. :P
<FromGitter>
<r00ster91> z64: it works for me. Are you sure you updated to 0.28.0?
<z64>
i'm using the official 0.28 docker image.
<FromGitter>
<r00ster91> thats strange
<Jenz>
And `arr[..]` is pretty cool, sure it's no use to do it like so (as it's the same as just `arr`), but with something like `r = cond ? 3..10 : ...` then `arr[r]`
<z64>
um, nevermind, seems to work now. weird
* Jenz
O_o
<FromGitter>
<Blacksmoke16> :trollface:
<FromGitter>
<tenebrousedge> @Jenz, are you going through the Crystal track on exercism?
Raimondi has joined #crystal-lang
<Jenz>
Yeah, I'm of your irritating students, right now you're reviewing the main track Triangle exercise of mine, and you've helped greatly on the side track exercise Forth
<Jenz>
s/I'm of/I'm one of/
<FromGitter>
<tenebrousedge> I'm pretty sure you're my least irritating student :)
<Jenz>
Huh? Sounds weird, well, thanks I guess, I had always thought I must be very irritating
<Jenz>
Haha
alexherbo2 has quit [Ping timeout: 245 seconds]
<FromGitter>
<tenebrousedge> You know what you're doing. Yesterday I was reviewing some Ruby code that used `while` and an explicit counter to iterate through a string in-order. I think I've even seen someone use a `for` loop recently. And you know, I try to say nice things about the code I review, but sometimes it's a considerable effort
<FromGitter>
<j8r> @tenebrousedge do you use a linter to help you for this reviews?
<Jenz>
Haha, during the Forth review it was made quite clear you didn't like my until loop. I kept it :P
<FromGitter>
<tenebrousedge> @j8r not typically. I will often point people towards them or suggest things that e.g. `rubocop` would dislike, but I at least like to think that I've memorized those rules
<FromGitter>
<j8r> to some extend, you are a like a ++linter :)
<FromGitter>
<tenebrousedge> `until` and `while` should not be used when the number of iterations is knowable, as a general rule, but the rules aren't unalterable mathematical laws. To say that this is an empirical profession is probably overly generous: our rules are at best based on subjective experience, and at worst, everybody repeating the same thing
* Jenz
:o
<Jenz>
A very pragmatic and prophetic speech
<mps>
tenebrousedge: well told, +1
<FromGitter>
<tenebrousedge> so, I don't like either of those constructs, because they're forms of iteration that don't have the `Enumerable` methods available, and I think that's sort of limiting. However, they can also be necessary. I don't know that there is a way to write e.g. Pollard's rho algorithm for prime factorization without using a `while` loop. But either way, if someone else chooses to code using `while` loops, then I
<FromGitter>
... think that "I don't like that" is as much as I have any business in saying, and I think it's totally fine for someone else to have their own opinions on the matter
<FromGitter>
<Blacksmoke16> tbh i never used a while loop so far in crystal
<FromGitter>
<Blacksmoke16> :S
<Jenz>
I've used a lot of `until`-loops, but no `while`-loops AFAICR
<Jenz>
I like `until`-loops XD
<FromGitter>
<kinxer> I use while loops to wait for and handle socket communication. I don't think I've ever used them in Crystal outside of that.
<FromGitter>
<Blacksmoke16> while loop meaning loop forever then like `break if xxx`?
<FromGitter>
<Blacksmoke16> `while true` i mean
* Jenz
throws a `loop do` at Blacksmoke16
<FromGitter>
<Blacksmoke16> yea, thats what i was going to suggest
<FromGitter>
<Blacksmoke16> then he wont use them either ha
<FromGitter>
<kinxer> @Blacksmoke16 I can't find one of those that I've written (I've not done a lot of socket communication). I try to make it conditional on something that might actually change.
<FromGitter>
<kinxer> Often the loop is in another fiber (and has a blocking method in it), so it can be stopped by calling a method on some object.
<FromGitter>
<kinxer> I do like the syntax of `loop do`, but I don't think I've actually used it.
<FromGitter>
<j8r> I use `while` with buffer
<FromGitter>
<j8r> while the buffer isn't full, keep filling it
<FromGitter>
<tenebrousedge> I've used `loop do` in creating an `Enumerator` in Ruby. My tendency would be to wrap a low-level construct like that in something that I can use `map` on
<FromGitter>
<jwoertink> So I decided to take a stab at making a PR to the compiler... I'm definitely in over my head, but I'd really like to understand this stuff. Anyone around with some knowledge in this area available for some questions?
<FromGitter>
<Blacksmoke16> What part of the compiler?
<FromGitter>
<jwoertink> I'm currently poking around `src/compiler/crystal/semantic/call_error.cr`
<FromGitter>
<jwoertink> in `Crystal::Path`
<FromGitter>
<Blacksmoke16> 😬 never heard of it :p
<FromGitter>
<jwoertink> 😂
<FromGitter>
<jwoertink> We have a `Crystal::Path` and `Crystal::CrystalPath` .... not confusing at all 😆
<FromGitter>
<Blacksmoke16> One might be an internal thing while the other is exposed to the user?
<Jenz>
The second is the macro-time (or whatever it's called) type of a path literal (e.g YAML), while `Crystal::Path` is the compiler-internal type of a path
<Jenz>
I think
<FromGitter>
<Blacksmoke16> I remember seeing the former in some of my macro work
<Jenz>
I've always been a bit confounded by the Crystal module
<FromGitter>
<jwoertink> When you see the error "undefined constant Whatever", that "Whatever" part seems to be an instance of `Crystal::Path`
<FromGitter>
<jwoertink> which is the thing I'm wanting to change, but this class is so small, I don't know what I have access to
<FromGitter>
<jwoertink> And then there's this argument passed in to this method called `type` that seems to be a `Crystal::NumberLiteralType` which makes no sense to me
<FromGitter>
<jwoertink> but somehow this `Crystal::NumberLiteralType` knows how to take the `Crystal::Path` and figure out if it's a private constant or not 😖
<Jenz>
The more I look at this, the more I am confused, not by the Path implementation, but by the NumberLiteralType
<Jenz>
Are you sure there's nothing else that is causing a NumberLiteralType being passed to Crystal::Path#raise_undefined_constant ?
<FromGitter>
<jwoertink> I have it failing on my spec that I wrote
<FromGitter>
<jwoertink> I changed the `self.raise` to just do `self.raise("moo #{type.name}")`
<FromGitter>
<jwoertink> > undefined method 'name' for Crystal::NumberLiteralType (compile-time type is Crystal::Type+)
<FromGitter>
<jwoertink> though... it is a compile error... so maybe it's not what I'm thinking...
<Jenz>
There seems to be this weird interchangeability between Types and Constants, I'm just throwing random thoughts
<FromGitter>
<jwoertink> It's definitely a bit confusing at first glance. I'm sure it becomes easier the more you poke around in this
go|dfish has joined #crystal-lang
<FromGitter>
<0x2C6> how can I change encoding? I know crystal uses utf8 by default but when I try to render a letter as a json it returns weird characters on the browser(Safari) How can I change this encoding?
Jenz has quit [Ping timeout: 245 seconds]
<FromGitter>
<kinxer> Do you know what encoding you need?
<FromGitter>
<Blacksmoke16> also having some additional methods on `Annotation` type would be nice, like im thinking `size`, `keys`, `values`?
<FromGitter>
<Blacksmoke16> where like size would be the number of total arguments, keys would be keys of named args, and values would be all positional and values of named arguments
<FromGitter>
<Blacksmoke16> would be better if you could only have positional OR named arguments tho...
<FromGitter>
<Blacksmoke16> main use case is allow iterating over each positional argument, which atm is not possible unless you know the exact number of values ahead of time
<FromGitter>
<Blacksmoke16> prob write up an issue for this later
<FromGitter>
<0x2C6> For example I'm gonna render something and result is that {"currency":"1 CÉ™nubi Afrika randı"} it should be "1 Cənubi Afrika randı" I know maybe it's not about the crystal but maybe someone knows why. I encountered with this problem in safari browsers. Chrome is okay
<FromGitter>
<bew> @Blacksmoke16 about positional args, it's expected, regular method call has the same logic
<FromGitter>
<Blacksmoke16> gotcha, so its really just up to the user to not do something stupid :P
<FromGitter>
<kinxer> @0x2C6 Could you give some example Crystal code of how you're creating and outputting your json?
lucasb has quit [Quit: Connection closed for inactivity]
<Jenz>
I've never really used the HTTP client, but glancing at the docs, there's this: file:///usr/share/doc/crystal/api/HTTP/Client/Response.html#charset%3AString%3F-instance-method
<Jenz>
Oh, that might be the other way around
<Jenz>
As mentioned, I don't really know what I'm doing, but maybe `context.response.headers["Content-Type"] = "application/json; charset=utf-8"`
<FromGitter>
<Blacksmoke16> thats one way to do it yes
<FromGitter>
<Blacksmoke16> `context.response.content_type = "application/json; charset=utf-8"` would prob also do the trick
<FromGitter>
<Blacksmoke16> which internally does the same thing
* Jenz
:D
<FromGitter>
<Blacksmoke16> :p
<Jenz>
I'd never thought I was right, haha
<Jenz>
Thanks for the clarification
<FromGitter>
<Blacksmoke16> `ctx.response.headers.add "Content-Type", "application/json; charset=utf-8"` also works :S
<Jenz>
As does `ctx.response.headers.merge!(HTTP::Headers.new.tap &.[]=("Content-Type", "application/json; charset=utf-8"))` -- I think
* Jenz
:z
<FromGitter>
<Blacksmoke16> oh boy
<Jenz>
Not that it's a very good idea haha
sz0 has quit [Quit: Connection closed for inactivity]
Jenz has quit [Quit: leaving]
<FromGitter>
<drum445> Hi all, does anyone know why in kemal `env.redirect` doesn't exit the block?
<FromGitter>
<drum445> it runs the code below it :O
<sagax>
hi all!
<sagax>
we have some little examples with small programs?
<FromGitter>
<Blacksmoke16> examples of anything in particular?
<FromGitter>
<dscottboggs_gitlab> are you looking for examples or saying that you have produced some @sagax?
<FromGitter>
<dscottboggs_gitlab> there is a really nice collection as a part of the source tree
<sagax>
with some specific target
<sagax>
thanks, will be see
<FromGitter>
<dscottboggs_gitlab> I posted the link above
<FromGitter>
<Blacksmoke16> so i made some breaking but nice changes to CrSerializer
<FromGitter>
<Blacksmoke16> i realized i could have done `delegate assertions, errors, invalid_properties, valid?, validate, to: @validator`
<FromGitter>
<Blacksmoke16> so now you can just do like `model.valid?` vs `model.validator.valid`
<FromGitter>
<Blacksmoke16> also the module is now a generic, so if you want to support JSON format you do `include CrSerializer(JSON)`, for YAML `include CrSerializer(YAML)`, for both `include CrSerializer(JSON | YAML)`
<FromGitter>
<Blacksmoke16> 💯
<FromGitter>
<Blacksmoke16> or if you dont want any can just but some garbage in like `include CrSerializer(Int32)` or whatever