ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.33.0 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
return0e_ has quit []
gangstacat has quit [Ping timeout: 246 seconds]
gangstacat has joined #crystal-lang
return0e has joined #crystal-lang
return0xe has joined #crystal-lang
return0e has quit [Ping timeout: 264 seconds]
<FromGitter> <smalls12> is there any documentation regarding working with `time_t` from C code ?
<FromGitter> <smalls12> I have some C calls that require a `time_t` struct
<watzon> @smalls12 well it doesn't seem like that struct exposes any fields publicly, so I assume you just need to pass it around right?
<watzon> You can use use a void pointer
return0xe has quit [Remote host closed the connection]
<FromGitter> <smalls12> yea was having a bit of a brain fart
<watzon> No worries lol. I'm wrapping a C library right now too.
<watzon> Working on more comprehensive bindings for ImageMagick
<FromGitter> <smalls12> : )
<watzon> I always feel like I learn so much by doing a deep dive into libraries like this
<watzon> ImageMagick has more than I knew
_ht has joined #crystal-lang
teardown has quit [Ping timeout: 258 seconds]
_whitelogger has joined #crystal-lang
sagax has joined #crystal-lang
return0xe has joined #crystal-lang
zorp has joined #crystal-lang
<FromGitter> <stronny> do we have a libindicator bindings?
<FromGitter> <stronny> or maybe I'm not getting the right picture. some way to make use of indicator-applet of a gtk panel?
<FromGitter> <stronny> basically I want to show an icon in a linux "tray"
alexherbo2 has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> I thought this was valid syntax? https://carc.in/#/r/8qvn
<FromGitter> <Blacksmoke16> gotta put the `.` in front of it
<FromGitter> <dscottboggs_gitlab> aahhhh thank you
<FromGitter> <Blacksmoke16> i asked this before i think, but what are people's thoughts on this
<FromGitter> <Blacksmoke16> for my validation shard after validating something it'll return `Array(ConstraintViolationInterface)`
<FromGitter> <Blacksmoke16> would it be worth it to make some type wrap the array
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e7636f841f2ab3f843ac6a3]
<FromGitter> <Blacksmoke16> or just skip that and allow people to interact directly with the array
<FromGitter> <smalls12> on a more general note, what is the use case for that shard?
<FromGitter> <smalls12> what do you intend to validate
<FromGitter> <dscottboggs_gitlab> @Blacksmoke16 it looks like an API for a Set, not an Array
<FromGitter> <Blacksmoke16> @dscottboggs_gitlab i suppose thats one of the advantages of the API, abstracts how its actually implemented
<FromGitter> <Blacksmoke16> @smalls12 objects/values against constraints
<FromGitter> <Blacksmoke16> example
DTZUZU has quit [Quit: WeeChat 2.7]
<FromGitter> <smalls12> ah ok thanks
<FromGitter> <dscottboggs_gitlab> That looks really useful and easy to use, what about defining a Constraint and ConstraintValidator though?
<FromGitter> <Blacksmoke16> hm? thats how it works atm
<FromGitter> <dscottboggs_gitlab> I mean, what is that API like? To define a custom Constraint
<FromGitter> <Blacksmoke16> ah
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e763ecd4f537701a0b6f9c9]
<FromGitter> <Blacksmoke16> the constraint would map to an annotation in some TBD way
<FromGitter> <Blacksmoke16> so like in this case it would allow doing `@[NotBlank(allow_nil: false)]`
DTZUZU has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> > add_parameter("{{ value }}", value.to_s) ⏎ ⏎ Hm?
<FromGitter> <Blacksmoke16> each violation has a `@parameters={"{{ value }}" => ""},`
<FromGitter> <dscottboggs_gitlab> not bad in general. I could probably find a use for it in a larger project
<FromGitter> <Blacksmoke16> this would allow you to do placeholders in the message
<FromGitter> <dscottboggs_gitlab> Oh I see, that's nifty
<FromGitter> <Blacksmoke16> `@[NotBlank(message: "The value {{ value }} is blank")]`
<FromGitter> <Blacksmoke16> longer term this would go thru some translator service, but for not prob just going to be `.gsub`
<FromGitter> <dscottboggs_gitlab> sounds great
<FromGitter> <Blacksmoke16> a violation essentially is just a bunch of metadata about the failure. the user of it could do what they want
<FromGitter> <Blacksmoke16> i.e. make some exception take it to build our an error response, etc
<FromGitter> <Blacksmoke16> https://symfony.com/doc/current/validation.html is what im kinda using as a base
<FromGitter> <dscottboggs_gitlab> maybe you could do like ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e76406825555d195ebb42ce]
<FromGitter> <Blacksmoke16> what would that do?
<FromGitter> <dscottboggs_gitlab> provide you an easy way to register the constraint while abstracting the special naming scheme so that a user doesn't have to know how that all works
<FromGitter> <dscottboggs_gitlab> > ``` ⏎ class Author ⏎ { ⏎ ⏎ ```You and your damn php lol``` [https://gitter.im/crystal-lang/crystal?at=5e7640d50e3d786afafb5db8]
<FromGitter> <Blacksmoke16> has some cool stuff 😉
<FromGitter> <Blacksmoke16> i also might just go with like
<FromGitter> <dscottboggs_gitlab> I'll just hang out here and wait for you to port it all to Crystal thank you very much 😀
<FromGitter> <Blacksmoke16> ```struct NotBlank < Constraint ⏎ ANNOTATION = Assert::NotBlank ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e76411832150c1454f23f6f]
<FromGitter> <Blacksmoke16> or
<FromGitter> <Blacksmoke16> ```@[AVA::Register(Assert::NotBlank)] ⏎ struct NotBlank < Constraint ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e764134bcd4df626317b2b3]
<FromGitter> <Blacksmoke16> idk yet
<FromGitter> <Blacksmoke16> php land has it easier as the constraint is the annotation
<FromGitter> <Blacksmoke16> versus having to map two types to the same name somehow
<FromGitter> <Blacksmoke16> or could just define all constraints as annotations in some common `Assert` namespace?
<FromGitter> <Blacksmoke16> that would prob be fine
<FromGitter> <Blacksmoke16> anyway, yes/no on the `ConstraintViolationListInterface`? I'm thinking yes
<FromGitter> <dscottboggs_gitlab> 👍 Agreed but I still think a set should back it
<FromGitter> <Blacksmoke16> hmm is there any case where there could be duplicate constraints and you would want there to be 2 violations tho?
DTZUZU2 has joined #crystal-lang
DTZUZU has quit [Ping timeout: 246 seconds]
JuanMiguel has joined #crystal-lang
<oprypin> what would my options be for installing an old version of Crystal on Ubuntu?
alexherbo2 has quit [Read error: Connection reset by peer]
alexherbo23 has joined #crystal-lang
JuanMiguel has quit [Quit: Saliendo]
<watzon> oprypin: asfd should work
<watzon> asdf*
<watzon> Or crenv, but I haven't really used that
<watzon> Man ImageMagick is huge https://github.com/watzon/pixie
<FromGitter> <dscottboggs_gitlab> oh wow. yeah, I'm sure
DTZUZU2 has quit [Ping timeout: 246 seconds]
DTZUZU2 has joined #crystal-lang
<watzon> I like the logo I came up with though 😁
<FromGitter> <jwoertink> Does anyone here know with the built-in crystal HTTP::Request#remote_address method, where that value comes from?
<FromGitter> <jwoertink> I'm looking at the spec here https://github.com/crystal-lang/crystal/blob/71cd3c5b7b875f38def0fe0f906cfb37a24ef927/spec/std/http/server/server_spec.cr#L450 but it looks like all kinds of stuff going on
<FromGitter> <jwoertink> I thought it just came from the `REMOTE_ADDRESS` header, but looks like it doesn't
<FromGitter> <jwoertink> what I'm trying to do here is I want to test something, and I want to set that value, and test for it, but I only have access to the context with `HTTP::Request.new` and the response
<FromGitter> <jwoertink> oh, I can just assign it to the request object
<FromGitter> <jwoertink> cool, that works
<FromGitter> <jwoertink> hashtag rubberduck
<sorcus> Hi guys.
<FromGitter> <dscottboggs_gitlab> hi
<watzon> sorcus: 👋
<sorcus> `Unhandled exception: Unsupported HTTP version: HTTP/2 (Exception)` - should be `HTTP/2` added to HTTP::SUPPORTED_VERSIONS?
<FromGitter> <dscottboggs_gitlab> @jwoertink I think that value is checked for in a few locations, like `X-Remote-Address` etc
<FromGitter> <dscottboggs_gitlab> hahahaha
<FromGitter> <dscottboggs_gitlab> good luck, sorcus
<FromGitter> <dscottboggs_gitlab> apparently http/2 is wayyy more complicated than 1.1
<sorcus> dscottboggs_gitlab: Oh, sorry. I mean how can i parse a string, that contain raw data. Like this - https://gist.github.com/MrSorcus/6d11117118e01a0ecef79636b524e264
<sorcus> dscottboggs_gitlab: https://gist.github.com/MrSorcus/b29865c70b7cb790db9744d72ab50fa1 - this works if i add "HTTP/2" to `HTTP::SUPPORTED_VERSIONS`, but i'm not sure that is a right way.
<FromGitter> <dscottboggs_gitlab> I feel like it would be better to try changing the request value to `HTTP/1.1` than to add `HTTP/2` to supported versions. An `HTTP/2` request can contain only things that are valid for `HTTP/1.1` so it's worth a shot either way. Just be sure you wrap the exception and note why it's being thrown, because it probably will fail at some point.
<FromGitter> <Blacksmoke16> not actually true ^
<FromGitter> <Blacksmoke16> `HTTP/1.1` headers are case insensitive, while in `HTTP/2` they should be lowercase
<FromGitter> <dscottboggs_gitlab> ^ this dude often knows more than me
<FromGitter> <Blacksmoke16> granted idk much about `HTTP/2` but that one is one diff im aware of
<FromGitter> <Blacksmoke16> oh wait i misread i think
<FromGitter> <dscottboggs_gitlab> does what I said make sense, with that in consideration? like yes, for that request, it makes sense to just say "yup this is ok" but if a server is expecting to be able to serve up 2 and you're trying to parse it as 1.1 you will probably run into some weird stuff
<FromGitter> <jwoertink> HTTP/3 will end up being a thing before HTTP/2 becomes standard
<FromGitter> <jwoertink> Which I guess is going to be designed after QUIC? or something??
<FromGitter> <dscottboggs_gitlab> ayyup
<FromGitter> <dscottboggs_gitlab> because TCP isn't good enough, we've gotta put the handshaking into the HTTP protocol too
<sorcus> https://gist.github.com/MrSorcus/68aa6b2c069c4455edc4ad1f169e42ba - i make something like this for getting raw data.
<sorcus> So what should i do make for parsing raw response via HTTP::Client::Response without patching stdlib?
<FromGitter> <dscottboggs_gitlab> if the response is in `HTTP/2` I don't think there's a good answer in Crystal unfortunately.
<FromGitter> <dscottboggs_gitlab> perhaps you can request that the server respond only with `HTTP/1.1` in a header?
* FromGitter * dscottboggs_gitlab googles
<sorcus> dscottboggs_gitlab: Yeah, i can do it with `--http1.1` or `--http1.0`.
<FromGitter> <dscottboggs_gitlab> no I mean, perhaps in the request you can send a header which indicates to the server that the client can only understand 1.1
<sorcus> dscottboggs_gitlab: Hmm... `curl --help` -> `--http1.1 Use HTTP 1.1`
<FromGitter> <dscottboggs_gitlab> oh I see now
<FromGitter> <dscottboggs_gitlab> I can't find anything, I'd ask on stackoverflow or something if there is a way to request a particular HTTP version via a header
<sorcus> dscottboggs_gitlab: There is no header for switching HTTP version as i know. But can be switched with request line `GET / HTTP/1.1`
<FromGitter> <dscottboggs_gitlab> oh, that makes sense
alexherbo23 has quit [Ping timeout: 256 seconds]
<sorcus> dscottboggs_gitlab: https://gist.github.com/MrSorcus/a8c562a13a8d9d898e2a4dacd931482d - i took method `self.from_io?` from `src/http/client/response.cr` and modified it for my use case.
<sorcus> dscottboggs_gitlab: This should be a good solution i think...
<FromGitter> <dscottboggs_gitlab> `return nil` is the same as just `return`. Also I would put a `begin..rescue` block around the Response.new constructor, which logs an extra note if the `http_version == "HTTP/2"`, and then raises. ⏎ ⏎ otherwise looks solid
<sorcus> dscottboggs_gitlab: Thank you for your recomendations. :-)
<FromGitter> <dscottboggs_gitlab> no problem, hope I've helped a little
<sorcus> dscottboggs_gitlab: Yeah, your help is very useful for me.
<FromGitter> <dscottboggs_gitlab> thanks! 😀
_ht has quit [Quit: _ht]
<sorcus> Good night :-)
<FromGitter> <smalls12> Channels have a non-blocking parameter, im guessing that means that when you call send/receive it will return instantly instead of sitting there
<FromGitter> <smalls12> ( whoops that was a question )
<FromGitter> <Blacksmoke16> right, afaik it would return `nil` if there is no value currently available to receive, otherwise returns that value
<FromGitter> <Blacksmoke16> i lied
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Channel.html#receive?-instance-method thats what i thought this did
<FromGitter> <smalls12> what would it return if nothing was there ?
<FromGitter> <smalls12> im just playing around with fibers, I have the blocking version working but non-blocking seems like a better idea
<FromGitter> <Blacksmoke16> well i thought it returned `nil`, but it actually blocks
<FromGitter> <smalls12> well thats weird
<FromGitter> <smalls12> non-blokcing blocks
<FromGitter> <Blacksmoke16> its not really non-blocking, just doesnt raise if the channel is closed/closes while waiting
<FromGitter> <uuwa> Would it be considered bad taste/practice to add parenthesis to every function/method call, even if it doesn't receive arguments?
<FromGitter> <Blacksmoke16> pretty sure the formatter would remove them
<FromGitter> <uuwa> I feel more comfortable doing it that way
<FromGitter> <uuwa> Oh, would it? I haven't checked that
<FromGitter> <Blacksmoke16> yes
<FromGitter> <uuwa> You're right. sigh.