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
teardown_ has joined #crystal-lang
teardown has quit [Ping timeout: 240 seconds]
<FromGitter> <jwaldrip> Anyone see my question about ARM macs?
<FromGitter> <jwaldrip> i.e. the new m1 proc
teardown has joined #crystal-lang
<raz> i saw it, but don't know the answer
teardown_ has quit [Ping timeout: 240 seconds]
postmodern has joined #crystal-lang
teardown_ has joined #crystal-lang
teardown has quit [Ping timeout: 240 seconds]
teardown has joined #crystal-lang
teardown_ has quit [Remote host closed the connection]
teardown has quit [Ping timeout: 240 seconds]
teardown has joined #crystal-lang
deavmi has quit [Ping timeout: 268 seconds]
deavmi has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 260 seconds]
f1refly has joined #crystal-lang
avane has quit [Quit: ZNC - https://znc.in]
avane has joined #crystal-lang
<FromGitter> <watzon> Can you convert a UInt64 to a UInt32 and have it overflow rather than throwing an error?
<FromGitter> <Blacksmoke16> `.to_u32!`
<FromGitter> <Blacksmoke16> try that
<FromGitter> <watzon> Ahh nice
_whitelogger has joined #crystal-lang
<FromGitter> <watzon> Always back to this same issue when I try to make a MTProto library. I need a way to take a byte slice and convert it to a BigInt in the same way you can convert a byte slice to any of the standard integer formats using `IO::ByteFormat`.
<FromGitter> <watzon> In Python it's super easy because their int is of arbitrary size anyway, so you can just do `int.from_bytes` and it doesn't matter how many bytes there are
teardown has quit [Ping timeout: 240 seconds]
<FromGitter> <watzon> Ok I'm confused https://carc.in/#/r/a50y
<FromGitter> <watzon> Huh, so `BigEndian` gives the same value
<FromGitter> <watzon> Lol I got the system endian mixed up. Forgot it's usually BigEndian and not LittleEndian.
<FromGitter> <watzon> I think I figured out something. If I can refine this I could submit a PR. This would be really nice to have in the standard library https://carc.in/#/r/a51n
_ht has joined #crystal-lang
<hightower3> Hey if I have Pointer(X) which may be null, is there an equivalent of .try I can run on that, instead of having to go like v= ...Ptr(X)...; if v.null? ....
<oprypin> hightower3, pretty much no
<oprypin> hightower3, i had this piece `(v = @some_ptr) ? String.new(v) : nil`
<oprypin> which you can then `try` on or whatever
<hightower3> Yeah I remember that PR. Ok thanks
<sorcus> Hi.
<sorcus> https://gist.github.com/MrSorcus/40236598de1ed11e0ff46a225ae07151 - why this code return bad decrypt?
<hightower3> @bew what was the idea with @save_cap_extensions in unibilium.cr? (I mean, why save locally into this variable instead of always call unibilium's functions)
rocx1 has joined #crystal-lang
rocx1 has quit [Client Quit]
<FromGitter> <bew:matrix.org> Hey hightower3: that's oold code^^ I didn't even used it once to be honest. Re-reading it I think it was to avoid calling the lib too often, and stay in crystal land. Since the extension class is created from a terminfo instance, the extensions won't change during the lifetime of the program, so I figured they could be kept on crystal side. Also, keep in mind that calling the lib for a string capability
<FromGitter> ... wouod always require to re-create a String obj on crystal side, which is not a free-operation. So i wanted to cache it to only do it once
<hightower3> @bew awesome, ok thanks. Yeah strings need to be recreated, true. I saw that while @extensions was created, it wasn't populated with actual extended capabilities. I added some code, might follow up with another PR for that at some point
<FromGitter> <bew:matrix.org> Alright! As I said a few times before I don't do much Crystal nowadays. Are you working on terminal libs? Are you willing to work on them? (I could transfer ownership if you want)
<hightower3> @bew Yes, working on these things... I am decided on using unibilium.cr primarily because it has the .format/.run functions, which would be a real pain to do in Crystal. I will send you an email re. transfer. Is the Epit... email address OK?
<FromGitter> <bew:matrix.org> I started a pure crystal implementation actually, the repo is terminfo.cr iirc, I have a format/run implementation as a PR (still missing the last mile (and good tests..) but the parser is there if you're interested
<hightower3> sure, by all means
<FromGitter> <bew:matrix.org> Yes that email address is ok, I never use it anymore but i receive emails. Is that you who sent an email aboit term libs some time ago? (sorry didn't respond)
<hightower3> yes, no worries (you can ignore)
<hightower3> (also btw unibilium development continued, it's not abandoned any more - https://github.com/neovim/unibilium )
<FromGitter> <bew:matrix.org> Yeah I know, I follow neovim dev closely (;
<hightower3> sent the email, thanks
<FromGitter> <anthonyshull> i would be interested if anyone has a take (or link to an article) on using crystal for web development, especially compared to elixir
<FromGitter> <anthonyshull> i have an api that is wrought with crazy differences in the way that status codes, response shapes, etc. are handled
<FromGitter> <anthonyshull> and am interested in creating a translation or anti-corruption layer on top of it
<FromGitter> <Blacksmoke16> have quite a few web frameworks to choose from, take your pick :p
<FromGitter> <anthonyshull> and that entails writing a lot of annoying rules like...parse a location and if all of the fields of the location are null then location is null, etc.
<FromGitter> <anthonyshull> well, i would have to make a pretty big argument for using crystal over something like elixir
<FromGitter> <anthonyshull> so i'm wondering if anyone has written anything about what crystal web development excels at
<FromGitter> <Blacksmoke16> perf, type safety, nice syntax. The usual stuff
<FromGitter> <Blacksmoke16> ofc downsides being less mature ecosystem
<FromGitter> <anthonyshull> is there a crystal rules engine?
<FromGitter> <Blacksmoke16> hm?
<FromGitter> <anthonyshull> i used clojure's clara rules to parse obnoxious data before and it was really quite nice
<FromGitter> <Blacksmoke16> imma go with prob not
<FromGitter> <anthonyshull> better than a shit load of code all over the place with if/else statements
<FromGitter> <anthonyshull> well, part of what i like about crystal is that it isn't so mature that everything has already been written :)
<FromGitter> <anthonyshull> http://www.clara-rules.org/
<FromGitter> <anthonyshull> writing something similar in crystal would be a fun holiday project
<FromGitter> <Blacksmoke16> wew, i have no idea what im reading there
<FromGitter> <anthonyshull> haha, i have an implementation example
<FromGitter> <anthonyshull> for things like...if the direction is west and it is after noon then the meal is beef
<FromGitter> <anthonyshull> in oil and gas we had crazy rules like that that would have been a PITA to write as application logic
<FromGitter> <Blacksmoke16> ha, idk ⏎ ⏎ ```if direction.west? && time > noon ⏎ meal = :beef ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5fde18a02084ee4b785e2990]
<FromGitter> <Blacksmoke16> seems a lot simpler than that :p
<FromGitter> <anthonyshull> yeah, until you get into the hundreds of rules
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <anthonyshull> also note that the pattern is reusable across projects. even if you created your own rules module it wouldn't be useful anywhere else.
<raz> blacksmoke: can i access the view_context from inside a controller method somehow? sometimes i want to change the status code
<FromGitter> <Blacksmoke16> `@[ART::View(status: :accepted)]`
<raz> yea, but what when i need to change it afterwards?
<raz> e.g. 200 vs 201
<FromGitter> <Blacksmoke16> afterwards?
<raz> inside the method
<FromGitter> <Blacksmoke16> like you want the code to be dynamic based on some logic in the method?
<raz> yes, the method may create or update, so it should return 200 or 201
<FromGitter> <Blacksmoke16> would it not be better to have separate POST and PUT endpoints?
<raz> sometimes clients can't know whether a resource already exists
<FromGitter> <anthonyshull> might be a classic upsert situation where the user doesn't know
<FromGitter> <anthonyshull> oh, beat me to it
* raz hi5s anthony
<FromGitter> <anthonyshull> you don't have access to the response object in the controller? i have zero experience with crystal frameworks
<FromGitter> <Blacksmoke16> i think you have 2 options raz
<raz> well soon i will, the framework author is grinding his head right now :p
<FromGitter> <Blacksmoke16> 1, use an `ART::Response` directly
<FromGitter> <Blacksmoke16> 2, add like `request : HTTP::Request` as an action argument and then can do like `request.action.view_context.status = ...`
<FromGitter> <Blacksmoke16> although id personally go with 1
<raz> but isn't `action` an instance of my controller anyway?
<FromGitter> <Blacksmoke16> action is an instance of a class to represents the controller action that the current request matched
<FromGitter> <Blacksmoke16> that represents*
<raz> 🤯
<FromGitter> <Blacksmoke16> just feels a bit hacky
<FromGitter> <Blacksmoke16> like i could see it breaking if i ever remove the action from the request obj
<raz> yea i feel like controllers should just have access to the view_context directly. wanting to override the response status (or perhaps throwing in a header) isn't an exotic requirement 🤔
<raz> having to construct a whole new Response from scratch would bypass all the nice serialization magic in my carefully crafted ViewListener
<raz> see how i use your own vocabulary against you! 😝
<FromGitter> <Blacksmoke16> no, but i think basing it off of runtime logic of the request is less common
<raz> hmm, upserts are pretty common in REST
* FromGitter * Blacksmoke16 has a thought
<FromGitter> <anthonyshull> yeah, an example from amber
<FromGitter> <anthonyshull> would just set the status code in the create
<FromGitter> <Blacksmoke16> where does it do that?
<raz> in the `update`
<FromGitter> <Blacksmoke16> i only see it settings it to 400 on error
<FromGitter> <Blacksmoke16> setting
<raz> well the point is, it lets you set it ;)
<FromGitter> <Blacksmoke16> not exactly a 1:1 comparison
<FromGitter> <Blacksmoke16> but i may have a solution
<FromGitter> <Blacksmoke16> a symfony extension has a concept of a `View Layer`. Of which the default `ART::Listeners::View` is a very basic implementation of that
<raz> 🤔
<FromGitter> <Blacksmoke16> but tl;dr could do something like `self.view data, status: status`
<FromGitter> <Blacksmoke16> i.e. similar to `ART::Response` but still invokes the view layer, acting as just a wrapper around the data/status/headers
<raz> yup, that would make sense to me
<raz> basically just `self.view.status = 418` in my controller method
<FromGitter> <Blacksmoke16> *kinda*, where `self.view data, status, headers` returns a `View` instance
<raz> hum, does the view not exist yet when my controller method runs?
<FromGitter> <Blacksmoke16> right, as i said it would be similar to `ART::Response`, but instead of representing the actual response that should returned; it represents the data, status, headers in a format agnostic way
<FromGitter> <Blacksmoke16> kinda like how if you just return a scalar object, but a bit more customizable. i.e. setting the headers/status
<raz> hum, i'm just confused because in `ViewListener` you grab the status from `action.view_context.status`. since `action` is my controller (or something that points to it) i wonder why i can't just get access to `view_context` in there, to set the status (or other stuff) when needed.
<FromGitter> <Blacksmoke16> sorry, what im talking about isnt implemented yet
<FromGitter> <Blacksmoke16> you can using option 2 i mentioned above
<FromGitter> <Blacksmoke16> but i think its not ideal
<FromGitter> <Blacksmoke16> idk, have some thinking to do
<raz> well, it's weird because it requires an extra argument 🤔
<FromGitter> <Blacksmoke16> exactly :p, hence a bit hacky
<raz> couldn't `ART::Controller` just have a helper method `view` or `view_context` that gives me that?
<raz> or is it not reachable through the magic layers? ;)
<FromGitter> <Blacksmoke16> yes but would just be moving the hack to behind the scenes versus fixing it in a more robust way
* raz scratches head
<FromGitter> <Blacksmoke16> that type is more of an artifact of needing something to store the values from the annotation
<FromGitter> <Blacksmoke16> since they cant be read at runtime
<raz> hmm yea, i guess i just don't see how it's hacky, as i assume action always has a view/view_context. so it would seem like just a matter of exposing it with a helper. but... i'm probably missing sth in between all the dep injection magic ;)
<FromGitter> <Blacksmoke16> the hacky part is you need to get it from the current request
<raz> hmmm ahh
<FromGitter> <Blacksmoke16> and what im getting at is it would make that an implementation detail and give the user something easier to work with
<FromGitter> <Blacksmoke16> and with a more stable API
<raz> hmm yup, whatever let's me change the status code from inside the ctrl-method (without creating a whole new response) is fine with me.
<FromGitter> <Blacksmoke16> 👍
<raz> i like that i can just return a Hash() or whatever, and let the ViewListener serialize it. the only missing thing is that i need to tell the ViewListener what response code to use
<raz> (or more generalized, perhaps even a general way to pass parameters back to the ViewListener from inside the ctrl method, that the VL impl can then do whatever with)
<raz> s/pass back/set parameters that the VL can pick up/
<FromGitter> <franciscoadasme> hey everyone, `crystal docs` is getting stuck without any output on my repo... how could I debug it?, I have no idea what could be the issue
<straight-shoota> there's no log output for crystal docs
<straight-shoota> so probably strace is the best idea
<FromGitter> <franciscoadasme> how so?
johnny101 has quit [Ping timeout: 256 seconds]
<straight-shoota> strace crystal docs
<straight-shoota> it prints all the system calls
<straight-shoota> so expect a lot of data
<straight-shoota> prob best to pipe in a file
<FromGitter> <jrei:matrix.org> Also, you could try to crystal docs every file individually
<straight-shoota> or only look at the last lines, that's probably the intersting part
<FromGitter> <jrei:matrix.org> But maybe 2 files are producing the bug
<straight-shoota> and individual files would still not show what's wrong, even if it's not caused by a combination
<FromGitter> <jrei:matrix.org> Yes, but it reduces the issue a lot
<FromGitter> <jrei:matrix.org> Also, another option is bisect your repo
johnny101 has joined #crystal-lang
<FromGitter> <franciscoadasme> Testing different files I found a file that reproduces the issue, and deleting sections I found that `crystal docs` gets stuck when generating methods using macro on an Enum
<FromGitter> <franciscoadasme> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5fde2ec6c746c6431cc47010]
<FromGitter> <franciscoadasme> do you have an idea why it gets stuck or should I post an issue?
<straight-shoota> please report this isuee
ua_ has quit [Ping timeout: 264 seconds]
ua_ has joined #crystal-lang
<FromGitter> <anthonyshull> do any of the major web frameworks support some kind of middleware or plugin system?
<FromGitter> <anthonyshull> don't see anything in the guids for amber or lucky
<FromGitter> <Blacksmoke16> in those they're called plugs
<FromGitter> <Blacksmoke16> er
<FromGitter> <Blacksmoke16> pipes
<FromGitter> <Blacksmoke16> in amber at least
<FromGitter> <bew:matrix.org> hightower3: to transfer ownership it seems you need to delete your own fork (otherwise it says "docelic/unibilium.cr" already exists), or maybe just rename it, it should work as well
<FromGitter> <Blacksmoke16> kemal also uses the http handler concept. Athena uses a more event/listener based approach
<FromGitter> <anthonyshull> interesting, awesome
DTZUZU has joined #crystal-lang
<hightower3> @bew removed
<FromGitter> <bew:matrix.org> okay, did you see my email about terminfo?
<FromGitter> <bew:matrix.org> started transfer, you should have received a notification or something I think
<hightower3> done; you can do terminfo.cr at the same time. In the meantime I'm responding to the email
<FromGitter> <bew:matrix.org> you should have a request for the other repo (and another email :D )
_ht has quit [Read error: Connection reset by peer]
_ht has joined #crystal-lang
<sorcus> https://gist.github.com/MrSorcus/40236598de1ed11e0ff46a225ae07151 - why this code return bad decrypt? X-)
<oprypin> well how did you encrypt that??
<raz> pfft, can't you decrypt it in your head?
<raz> wrong iv clearly, i saw that on first glance
<sorcus> oprypin: "openssl enc -aes-256-cbc -salt -in hello.txt -a -out encrypted.txt -md sha256" - this is how i encrypt it.
<sorcus> raz: Hmm, i guess OpenSSL should extract iv when decrypt function called...
<raz> sorcus: how does it look w/o the salt?
<sorcus> raz: Or i should extract iv from encrypted text by self?
<raz> sorcus: no that was a joke. we just can't tell you what's wrong from a base64 blob...
<sorcus> raz: "openssl enc -aes-256-cbc -d -a -in encrypted.txt -pass pass:5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8" - how does openssl extract iv w/o the salt?
<sorcus> raz: blob just contain "Hello World!" string.
<raz> do you need to decrypt something that someone else sent you, or do you control both sides enc/dec?
<sorcus> raz: second.
<sorcus> raz: Well, but what about my example?
<sorcus> raz: It's a bug in openssl binding or i missed something?
<raz> most likely you missed something. sodium exists because openssl is hard
<sorcus> raz: Ok, thanks.
<raz> np. there really is no reason to use openssl unless you have to for compat reasons.
<hightower3> Hey @watzon I am trying out term-reader. Why does pressing things like a dot, comma, or ` generate two events instead of one?
<FromGitter> <watzon> This is a good question. I’ll have to look into it later. It’s been a while since I’ve touched it.
<hightower3> @watzon ah I see, for those keys, event.key.name == "". So when trigger_key_event() looks for all procs to invoke, the part: @event_handlers[key] + @event_handlers[""] actually results in twice calling a handler for ""
<hightower3> (this is when a handler is attacher for listening on any keys)
<hightower3> attached*
<hightower3> Also another question -- some of the escape sequences and following data into the term can be mouse input. Do you see this ever being part of/supported in term-reader, or how you'd approach that?
<FromGitter> <watzon> That is planned. I’ll probably be doing a complete overhaul of the system in the future by actually parsing terminfo
<hightower3> (on that note, bew and O have unibilium.cr and two versions of native terminfo parsers. For now I am using unibilium bindings which are functionally almost complete, although in the future the plan would be to join the native terminfo libs into one and make it have the same crystal api as unibilium, for transparent change)
<hightower3> O = I :)
_ht has quit [Remote host closed the connection]
<oprypin> (cc straight-shoota:) I'm working on a doc generator and struggling to implement linkification of type restrictions, like this one https://crystal-lang.org/api/0.35.1/Array.html#each_product(arrays:Array(Array),reuse=false,&)-class-method
<oprypin> crystal json only gives `"args_string": "(arrays : Array(Array), reuse = <span class=\"n\">false</span>, &)",`
<oprypin> I could edit crystal compiler to also generate links `"(arrays : <a href=\"Array.html\">Array</a>(<a href=\"Array.html\">Array</a>), reuse = <span class=\"n\">false</span>, &)",` which would help (i'd just use those as delimiters) but is probably not generic enough?
<straight-shoota> well, as I said the JSON output is lacking
<oprypin> straight-shoota, any suggestion for action?
<oprypin> i'd honestly be fine if it output this args_html
<oprypin> otherwise it requires some special kind of markup
<oprypin> xml of some sort
<oprypin> it's very curious how the output without links suspiciously seems to do syntax highlighting for everything except the parts that are meant to be linkified
<oprypin> straight-shoota, yeaa that's a mess
<straight-shoota> oh stop, you mean links inside the signature
<straight-shoota> but yeah, that's even more a mess
<straight-shoota> the only way forward I see is to formalize the data format and fix this mess
<oprypin> well i already said that i see at least one other way forward
<straight-shoota> hm, as a quick fix that might get you at least somewhere
postmodern has quit [Quit: Leaving]
<oprypin> can't be worse than args_string because that spews html already, just not in any useful shape
<oprypin> i had said > suspiciously seems to do syntax highlighting for everything except the parts that are meant to be linkified
<oprypin> and actually that part can just be conditional on `links: true` and that will make it not spew html into args_string
<oprypin> I'll send a proper PR
<FromGitter> <asterite> oprypin: what's your doc generator about?
<oprypin> asterite, https://github.com/oprypin/mkdocstrings-crystal - the readme just talks about the basic idea. i have a demo site but it's not a good showcase of the idea, just a basic 1:1 migration: https://oprypin.github.io/athena-website/Serializer/Context/
<oprypin> what it's about - well it's about replacing crystal's own generated api doc sites
<FromGitter> <jrei:matrix.org> looks nice oprypin!
<FromGitter> <jrei:matrix.org> remains the links on the methods
<FromGitter> <jrei:matrix.org> @Blacksmoke16: the [source] links on https://athena-framework.github.io/athena/index.html are broken
<FromGitter> <Blacksmoke16> only for the non athena routing ones
<FromGitter> <Blacksmoke16> nothing i can really do about it
<FromGitter> <jrei:matrix.org> why are they here?
<FromGitter> <Blacksmoke16> because i built the docs for athena + its required deps
<FromGitter> <Blacksmoke16> so everything links correctly
<FromGitter> <jrei:matrix.org> hum, they could have their own docs/pages
<FromGitter> <jrei:matrix.org> ha ok I see
<FromGitter> <Blacksmoke16> they do, as part of each specific shard
<FromGitter> <jrei:matrix.org> when we click on a type
<FromGitter> <Blacksmoke16> yea
coderobe has quit [Quit: Ping timeout (120 seconds)]
coderobe has joined #crystal-lang
hpyc9 has joined #crystal-lang