ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | 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
<FromGitter> <Daniel-Worrall> https://hub.docker.com/r/danielworrall/crystal aarm64 alpine images for building on ARM machines with docker :)
devoid_ has quit [Quit: WeeChat 3.1]
deavmi has quit [Ping timeout: 268 seconds]
deavmi has joined #crystal-lang
<FromGitter> <didactic-drunk> @wyhaines Listing forks (https://github.com/mamantoha/shards-info/issues/59). Chime in if you like.
jhass[m] has quit [Remote host closed the connection]
jhass[m] has joined #crystal-lang
Stephie- has joined #crystal-lang
hightower4 has joined #crystal-lang
Liothen_ has joined #crystal-lang
RobinStamer has joined #crystal-lang
[R] has quit [Read error: Connection reset by peer]
hightower3 has quit [Ping timeout: 264 seconds]
Liothen has quit [Ping timeout: 264 seconds]
Stephie has quit [Ping timeout: 264 seconds]
Liothen_ is now known as Liothen
<FromGitter> <mixflame> congrats on nearing windows support @straight-shoota
jhass[m] has quit [*.net *.split]
jhass[m] has joined #crystal-lang
hholst6543 has joined #crystal-lang
<hholst6543> Say I have multiple routes or methods for which I want to use the same code
<hholst6543> so, instead of typing get "/path1" do ... end and get "/path2" do ... end and duplicating some code, could I simply reference a subroutine there somehow?
hholst6543 has quit [Quit: Ping timeout (120 seconds)]
<FromGitter> <mattrberry> Having some trouble with ysbaddaden's sdl bindings. Just cut an issue here: https://github.com/ysbaddaden/sdl.cr/issues/41 Any help sorting this out would be appreciated. Not sure how active he is on that project anymore
<FromGitter> <naqvis> yes you can
<FromGitter> <wyhaines> ```code paste, see link``` ⏎ ⏎ You can create a method to encapsulate the repeated actions. [https://gitter.im/crystal-lang/crystal?at=60bc7a9c20e86942d2477e65]
<FromGitter> <naqvis> write a method which accepts context and params and return context
<FromGitter> <naqvis> @mattrberry sample code to reproduce the problem will help
hholst6543 has joined #crystal-lang
<FromGitter> <naqvis> better write some simple code which can reproduce the problem
arestifo has joined #crystal-lang
<FromGitter> <mattrberry> @naqvis Here you go. I'll post it on the issue too ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60bc7dee1e6aa460c0130ef8]
arestifo has quit [Client Quit]
<FromGitter> <rishavs> Is there any part of the request which can tell me if the connection is an http/https connection? I want to reroute all my http connections over to https
<hholst6543> hmm, is that part of the header?
<hholst6543> I typically do these kind of infrastructure things in the loadbalancer config, not in the application
<FromGitter> <Dan-Do> @rishavs I didn't try but something like this `request.resource.scheme`
<FromGitter> <rishavs> Thanks @Dan-Do . ⏎ @hholst6543, you are likely correct and i will likely end up doing the same later. But right now in dev, a small rerouting function will be good enough.
raz has quit [Ping timeout: 264 seconds]
raz has joined #crystal-lang
raz has quit [Changing host]
raz has joined #crystal-lang
<hholst6543> It would be great if the [@...] annotation stuff could be on the same line as the variable declaration
<hholst6543> it looks very verbose and somewhat opaque with two lines per variable declaration in a class or struct
<hholst6543> I think GoLang supports inline (as a suffix) annotations on structs
<FromGitter> <rishavs> I am trying to setup https on my dev server. ⏎ I used `openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout serverkey.pem -out servercert.pem` to generate the certificates and ⏎ ⏎ ```code paste, see link``` ⏎ ... [https://gitter.im/crystal-lang/crystal?at=60bc9a261e6aa460c0134601]
<FromGitter> <rishavs> any idea where i am messing up?
<FromGitter> <Dan-Do> I don't know insomnia, maybe it doesn't trust self-sign cert?
<FromGitter> <oprypin:matrix.org> @rishavs: there's really no reason to handle https in crystal. use nginx.
hightower4 has quit [Ping timeout: 245 seconds]
<FromGitter> <oprypin:matrix.org> and so also, I think, no reason to handle https in dev
<FromGitter> <rishavs> I am not really able to tackle samesite issues. So wanted to try setting up https
<FromGitter> <rishavs> I have a spa on 127.0.0.1:8080 and an api server at 127.0.0.1:3000
<FromGitter> <rishavs> No matter what samesite value I choose, the cookie gets rejected by teh browser
dostoyevsky2 has quit [Quit: leaving]
dostoyevsky2 has joined #crystal-lang
<FromGitter> <oprypin:matrix.org> @rishavs: i dont think https would help
<FromGitter> <oprypin:matrix.org> @rishavs: i would recommend to already try to merge them into one site. is this "spa" in a different programming language?
<FromGitter> <rishavs> vanilla js :D
krma has joined #crystal-lang
<hholst6543> you put a load balancer in front
<FromGitter> <rishavs> thats the plan once I go to prod. I will put my js on a CDN or on netlify. and put my server behind haproxy. and then throw a cloudflare caching layer on top
<FromGitter> <rishavs> but in the meantime, the samesite/cors stuff are making development a nightmare
<FromGitter> <rishavs> too much time waster on things that should have been non-issues
<hholst6543> Its true that the dev env is important
<hholst6543> it might still make sense to put a lb in the dev env
<hholst6543> you can have a common fake name and put the two different services as subdomains
<hholst6543> if you are using * that might be the problem youre seeing with the cookie,
<hholst6543> The value of "*" is special in that it does not allow requests to supply credentials, meaning it does not allow HTTP authentication, client-side SSL certificates, or cookies to be sent in the cross-domain request.[8]
<hholst6543> so you need to subdomain
postmodern has quit [Quit: Leaving]
hholst6543 has quit [Quit: Ping timeout (120 seconds)]
<FromGitter> <oprypin:matrix.org> > thats the plan once I go to prod. I will put my js on a CDN or on netlify. and put my server behind haproxy. and then throw a cloudflare caching layer on top ⏎ ⏎ why do you need to do any of those things?
<FromGitter> <oprypin:matrix.org> @rishavs
<FromGitter> <rishavs> Not sure I understood the question. I want to make a vanillajs spa, with crystal server for the backend. The layer in between will protect the api and provide caching
<FromGitter> <oprypin:matrix.org> @rishavs: how about this: just run 1 server and get it over with
hightower2 has joined #crystal-lang
<FromGitter> <Blacksmoke16> hholst6543: sometimes a little explicitness can be a good thing :) might help if you add some new lines between each set
<FromGitter> <naqvis> > @naqvis Here you go. I'll post it on the issue too ⏎ > ```crystal ⏎ > require "./src/sdl" ⏎ > ⏎ > event = SDL::Event.poll ... [https://gitter.im/crystal-lang/crystal?at=60bcc84c20e86942d2482813]
<FromGitter> <naqvis> one can easily reproduce similar behavior as below ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60bcc85d5e3ef60161e82202]
<FromGitter> <naqvis> technically speaking method `foo` can only be called on concrete instance of `Foo` and by that time compiler should have known the type for this, but my guess is that, when compiler reaches this line, it utilizes the ivar in context of parent class
<FromGitter> <naqvis> where there is no datatype attached, thus raising that issue
<FromGitter> <naqvis> workaround for this is to have this `foo` method in each concrete sub-class
<FromGitter> <naqvis> so for your use-case, you would have to define `to_unsafe` for each subclass of `Event`
sphinxc0re[m] has joined #crystal-lang
RobinStamer has quit [Quit: Gone.]
[R] has joined #crystal-lang
dostoyevsky2 has quit [Quit: leaving]
dostoyevsky2 has joined #crystal-lang
cbohw has joined #crystal-lang
cbohw has quit [Remote host closed the connection]
root has joined #crystal-lang
root has quit [Remote host closed the connection]
hholst6543 has joined #crystal-lang
hholst6543 has quit [Ping timeout: 250 seconds]
<FromGitter> <mattrberry> @naqvis I think the next trick is that I also need to get the `@event` then pass it to a binding that requires the a SDL_Event (which is mimicked here with `LibSDL::Event`). I don't think I can make each of the inheriting classes define their own to_unsafe like that since it seems like the crystal compiler doesn't really support unions properly for c bindings
<FromGitter> <naqvis> this is not specific to c bindings, as you can see above code in plain crystal
<FromGitter> <naqvis> so until unless there is a fix for that, you would have to stick to some workarounds
<FromGitter> <didactic-drunk> Is HTTPS server handling in crystal still DOSable?
<FromGitter> <naqvis> are you referring to any previous DOS issue?
<FromGitter> <naqvis> or referring to any known vulnerability?
<FromGitter> <mattrberry> I'm having trouble understanding how the workaround you mentioned helps in my specific context. I'm going to publish the code to github within the hour, so I'll send a link here soon and maybe you can take a look?
<FromGitter> <naqvis> let me try to put it this way. `SDL::Event` is an abstract class and have its all child classes defined inside it. `SDL::Event.poll` class method is going to return a concrete class which actually knows the type of `@event` ivar. When you invoke instance method `to_unsafe` which is defined in parent abstract class, compiler is having problem in identifying the type associated with that ivar (refer to my above
<FromGitter> ... sample code to reproduce the issue, and explanation behind that). So you are suggested to have that `to_unsafe` instance method moved to all sub-classes, where compiler won't yell at you about not knowing the type of `@event` ivar. Rest should remain same for your use-case and you can invoke ⏎ ⏎ ```event = SDL::Event.poll ⏎ ... [https://gitter.im/crystal-lang/crystal?at=60bd05781477ff6954a431ec]
<FromGitter> <mattrberry> Yeah that makes sense. The complication from that point is that I need to now call into another c binding that requires an SDL_Event*, which is what `LibSDL::Event` is meant to represent. If I make each of the inheriting event structs define their own `to_unsafe` that returns the specific types listed there, the Crystal compiler then doesn't know that `@event` on each of those is a `LibSDL::Event`
<FromGitter> <naqvis> how come?
<FromGitter> <oprypin:matrix.org> @mattrberry: I have a feeling like I would be able to solve the problem, but could you please point me to a clear statement of the problem?
<FromGitter> <mattrberry> Yeah I'm going to push this to github in just a sec once I clean up the makefile a little bit, then hopefully it'll be a little more obvious!
<FromGitter> <naqvis> Thanks @oprypin:matrix.org , just to give you a heads-up https://play.crystal-lang.org/#/r/bafd
<FromGitter> <oprypin:matrix.org> well ideally this wouldn't need to involve knowledge about makefiles but ok
<FromGitter> <mattrberry> Haha this specifically doesn't involve knowledge of makefiles, but my package will help give a more concrete example of what I'm trying to do
<FromGitter> <mattrberry> And I just want to clean a couple things up before pushing the code
<FromGitter> <Blacksmoke16> could also use a dev branch that you can just push to as needed while its WIP. Then when it's in a good state squash merge to master. Keeps a clean history on master but allows quicker/smaller commits
<FromGitter> <Blacksmoke16> (not related to this current issue, i just find that works well for how i dev)
<FromGitter> <oprypin:matrix.org> @naqvis: mm sorry that's too contrived to see the core of it. because I can easily say "just don't put the variable into the abstract class"
jcs has left #crystal-lang [#crystal-lang]
<FromGitter> <mattrberry> This is still super rough, but here's the package: https://github.com/mattrberry/crystal-imgui-backends ⏎ To install, you'll need to `make` twice because I suck with makefile lol. Then `shards install`, then `export LD_LIBRARY_PATH="$(pwd)/cimgui"; export LIBRARY_PATH="$(pwd)/cimgui"`. From there, you can `crystal build examples/imgui_impl_opengl3.cr`. Hopefully at that point it'll build properly and you
<FromGitter> ... can run `./imgui_impl_opengl3`. The problem comes when you uncomment the `ImGui::SDL2.process_event(event)` in examples/imgui_impl_opengl.cr
<FromGitter> <naqvis> i understand that's contrived example, but that's what I understand from the original context of question ⏎ ⏎ > Having some trouble with ysbaddaden's sdl bindings. Just cut an issue here: https://github.com/ysbaddaden/sdl.cr/issues/41 Any help sorting this out would be appreciated. Not sure how active he is on that project anymore
<FromGitter> <oprypin:matrix.org> so isn't https://github.com/ysbaddaden/sdl.cr/issues/41 the minimal example, then? do we still need https://github.com/mattrberry/crystal-imgui-backends ?
<FromGitter> <naqvis> i would say sdl raised issue should be sufficient, but i thought of reproducing that in plain crystal to avoid any extra noise of C bindings
<FromGitter> <oprypin:matrix.org> you're reproducing one approach to C bindings but there can be a different approach
<FromGitter> <naqvis> hmmm? isn't that the root cause?
<FromGitter> <mattrberry> https://github.com/ysbaddaden/sdl.cr/issues/41 can be resolved with @naqvis's approach of just moving the references to `@event` out of the abstract Event struct and into the inheriting structs. My next problem though is that I can't coerce any of the event types in lib_sdl.cr to be an Event
<FromGitter> <oprypin:matrix.org> sure. but my advice will not be "fixing" that root cause but removing the need for it
<FromGitter> <naqvis> 👍
<FromGitter> <naqvis> but I still believe you will be providing a workaround
<FromGitter> <naqvis> main point is to highlight the actual issue
<FromGitter> <naqvis> and IMO this is compiler bug
<FromGitter> <mattrberry> @oprypin:matrix.org Do you have an idea for how I might remove the need for it?
<FromGitter> <oprypin:matrix.org> yea i'm finishing that up
<FromGitter> <naqvis> while oprypin is working on a solution, i just verified that compiler actually does know the ivar and its type, but for some unknown reason , its still yelling at missing ivar type ⏎ https://play.crystal-lang.org/#/r/bagg
<FromGitter> <oprypin:matrix.org> @mattrberry: https://github.com/ysbaddaden/sdl.cr/pull/42
<FromGitter> <mattrberry> @oprypin:matrix.org That works, thank you :D
<FromGitter> <oprypin:matrix.org> @mattrberry: & I realize, you can just replace `e.to_unsafe` with `pointerof(e).as(LibSDL::Event)` and it will work in the current state
<FromGitter> <mattrberry> Hmm I tried that. It feel like that *should* work because the `@event` is just a value on the SDL::Event struct, but it doesn't seem to be passing the correct value still
<FromGitter> <mattrberry> Not a great test, but when I do it that way, imgui isn't able to read the keyboard inputs even though it compiles
<FromGitter> <oprypin:matrix.org> @mattrberry: what's `typeof(e)` when you tried
<FromGitter> <oprypin:matrix.org> im guessing `Event | Nil` which would indeed make it not work
<FromGitter> <oprypin:matrix.org> funnily enough, the `if` branch, even when used correctly and even when it removes the union, the underlying value is still a union, so that doesn't work
<FromGitter> <oprypin:matrix.org> i don't know. it really should work, though, because you're passing a copy of it through a method
<FromGitter> <mattrberry> I might be misunderstanding what you're saying. You're talking about the `SDL::Event`, right? And taking the pointer of that should really also be the pointer of the underlying `LibSDL::Event` since that's they only field on the struct?
<FromGitter> <oprypin:matrix.org> yes
<FromGitter> <mattrberry> ```code paste, see link``` ⏎ ⏎ Without your changes, this compiles but ImGui doesn't seem to be getting the correct value since it doesn't register any keyboard events. If I instead use the commented-out changes with your PR to sdl.cr, that works as expected [https://gitter.im/crystal-lang/crystal?at=60bd1b2284c2f15b7965842c]
<FromGitter> <oprypin:matrix.org> @mattrberry: hold on... that's a double pointer
<FromGitter> <oprypin:matrix.org> `to_unsafe` is wrong even with my changes
<FromGitter> <mattrberry> Ah I didn't see your second commit come in, perfect 👌
<FromGitter> <oprypin:matrix.org> @mattrberry: wait i don't understand, i completely remove `ImGui::SDL2.process_event(event)` from your example, but why do all mouse clicks continue workign fine?
<FromGitter> <oprypin:matrix.org> oh it must be polling the mouse by itself somehow
<FromGitter> <mattrberry> Yeah I think it polls the mouse itself, although I don't know details. If you open the "inputs" dropdown in the demo window, there's another dropdown for keyboard state. I've only gotten that one to work with your changes to sdl.cr
<FromGitter> <oprypin:matrix.org> yes i can reproduce something wrong there, cant see why yet
<FromGitter> <oprypin:matrix.org> @mattrberry: yea it needs to prepend a typeid and that interferes with stuff. well if you get desperate without the ability to fix sdl.cr, there's always the possibility to still take that pointer and offset it by one int's size to the right
hightower2 has quit [Ping timeout: 264 seconds]
<FromGitter> <me:ky.rs> hey all, been using crystal for quite a while now and finally decided to join the official channels :)
<straight-shoota> welcome =)
Guest64 has joined #crystal-lang
Guest64 has quit [Quit: Ping timeout (120 seconds)]
hightower2 has joined #crystal-lang
<FromGitter> <alex-kampa> what's the most efficient way to check if an array contains duplicates?
<FromGitter> <Daniel-Worrall> Probably `a.to_set.size == a.size`
<FromGitter> <alex-kampa> Cool, thanks! I'd be interested to know why you think this might be the most efficient way.
sphinxc0re[m] has left #crystal-lang [#crystal-lang]
<FromGitter> <alex-kampa> (apart from being the most concise)
<FromGitter> <Blacksmoke16> A set doesn't allow for duplicates
<FromGitter> <Blacksmoke16> So you'd inherently know by iterating once (to create the set)
<FromGitter> <alex-kampa> ok thanks daniel and george!
<FromGitter> <Daniel-Worrall> You might be able to get better if Sets allow for size preallocation
<FromGitter> <Blacksmoke16> theres an overload of `Indexable` https://github.com/crystal-lang/crystal/blob/1465a0b/src/set.cr#L44
<FromGitter> <Blacksmoke16> so yea, pre allocates the hash then iterates once adding each element to the set
<FromGitter> <Daniel-Worrall> If you need other information than just *if* there are duplicates, there are further optimisations with a custom block
hightower2 has quit [Ping timeout: 264 seconds]
repo is now known as repo[m]
repo[m] is now known as repo
repo is now known as repo1