faustinoaq changed the topic of #amber to: Welcome to Amber Framework community! | https://amberframework.org | Developer happiness, productivity and bare metal performance | GH: https://github.com/amberframework | Docs: https://docs.amberframework.org | Gitter: https://gitter.im/amberframework/amber | IRC Logger: https://irclog.whitequark.org/amber | Amber::Server.start
<FromGitter> <charleystran> what is the best way to sort an array of objects by a secondary relationship. I want to do something like game.players.sort{|a, b| a.rating.wins <=> b.ratings.wins } I think the null checking is beating me up
<FromGitter> <Blacksmoke16> could you do that in the query
<FromGitter> <charleystran> would I have to join first? if I do will it load the relation
<FromGitter> <Blacksmoke16> whats nil in what you have now?
<FromGitter> <charleystran> maybe I am wrong, and its a different problem. I am trying to sort the array and find if the item is in the top x positions and I get this `Error: undefined method '<=' for Nil (compile-time type is (Int32 | Nil))` for `players.sort{|a, b| a.wins<=> b.wins }.index(player) <= 2 ? 1 : 0`
<FromGitter> <Blacksmoke16> nope looks like its possible for `.wins` to be nil
<FromGitter> <Blacksmoke16> so you would have to handle that
<FromGitter> <Blacksmoke16> by making sure they are no nil before doing your comparison
<FromGitter> <Blacksmoke16> kinda makes me think would it make sense to have something in the stdlib to be able to handle that, id imagine it would just always be false vs compile error?
<FromGitter> <charleystran> yea, I would love nil to never beat a real value in a compare
<FromGitter> <charleystran> or if there was a way to default the value to 0, but I dont know know enough about crystal an amber yet
<FromGitter> <Blacksmoke16> oh yea
<FromGitter> <Blacksmoke16> `(a.wins || 0)`
<FromGitter> <charleystran> so like `players.sort{|a, b| (a.wins || 0)<=> (b.wins ||0) }.index(player) <= 2 ? 1 : 0`
<FromGitter> <Blacksmoke16> sure
<FromGitter> <Blacksmoke16> wait
<FromGitter> <Blacksmoke16> cant you just use https://crystal-lang.org/api/master/Array.html#sort_by(&block:T-%3EUNDERSCORE):Array(T)-instance-method
<FromGitter> <charleystran> maybe.... trying
<FromGitter> <Blacksmoke16> like `.sort_by { |player| player.wins || 0 }`
<FromGitter> <Blacksmoke16> would make more sense for you to define wins as not null with default of 0 tho?
<FromGitter> <charleystran> ok, I will try to do that. just trying to figure this all out :)
<FromGitter> <Blacksmoke16> np
feepbot has quit [Ping timeout: 245 seconds]
feepbot has joined #amber
<FromGitter> <nsuchy> ```code paste, see link``` [https://gitter.im/amberframework/amber?at=5d937dc224509b60468f5fcf]
<FromGitter> <nsuchy> any idea what's happening here
<FromGitter> <nsuchy> I download my app and run shards install
<FromGitter> <nsuchy> I'm told micrate requirements changed and to run shards update
<FromGitter> <nsuchy> afterwards that happens
<FromGitter> <nsuchy> it builds in a fresh docker image fine
<FromGitter> <nsuchy> which indicates an environment issue
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <nsuchy> ```code paste, see link``` [https://gitter.im/amberframework/amber?at=5d93975a290b8c354a0cf828]
<FromGitter> <nsuchy> yeah so specifically in debian
<FromGitter> <nsuchy> micrate has a build problem
<FromGitter> <eliasjpr> Did you try running `shards update` instead of `shards install`?
<FromGitter> <elorest> Micrate should be completely fixed as of yesterday.
<FromGitter> <nsuchy> I'm looking at Crystal's standard library right now, how do I go about rendering an http request's response quickly?
<FromGitter> <nsuchy> It's taking several seconds
<FromGitter> <elorest> What are you running it on? It only takes nanoseconds for me?
<FromGitter> <nsuchy> @elorest Desktop on docker
<FromGitter> <nsuchy> but my internet connection is 260mbps
<FromGitter> <nsuchy> on average
<FromGitter> <nsuchy> it shouldn't take long for a few kb of data
<FromGitter> <elorest> No.
<FromGitter> <elorest> Crystal, Kemal and Amber should be blazing fast.
<FromGitter> <nsuchy> @elorest I'm sorry, I mean sending an HTTP Request
<FromGitter> <nsuchy> not accepting traffic
<FromGitter> <nsuchy> I want to pull data from an API and include it in a rendered ECR template
<FromGitter> <Blacksmoke16> sure that api just isnt slow
<FromGitter> <elorest> If that's slow it's just because of the network traffic to the api.