ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.24.2 | 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
DTZUZO has joined #crystal-lang
thunker[m] has quit [Quit: removing from IRC because user idle on matrix for 30+ days]
<FromGitter> <girng> i know how to do sort_by! on an array
<FromGitter> <girng> but is it possible to do it on a hash? https://play.crystal-lang.org/#/r/40e4
<FromGitter> <girng> im trying to get the first Game_Server instance, that has the lowest `online_count` value
<FromGitter> <girng> i need to sort first, then do grab the first index `[0]`, right?
<FromGitter> <girng> err, should i say, key. since its a hash
betofloresbaca[m has quit [Quit: removing from IRC because user idle on matrix for 30+ days]
<FromGitter> <girng> ok look here: https://play.crystal-lang.org/#/r/40f2 im pretty close, but `find_first` is returning nil
<FromGitter> <Blacksmoke16> prob could just do
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/40ff
<FromGitter> <girng> ic
<FromGitter> <girng> thanks
<FromGitter> <girng> what's the difference between .each and .select?
<FromGitter> <asterite> or: https://play.crystal-lang.org/#/r/40fi
<FromGitter> <Blacksmoke16> or better yet
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/40fk
<FromGitter> <Blacksmoke16> ary beat me to it
<FromGitter> <Blacksmoke16> .each just iterates over each key/value in the hash, while select returns a new hash consisting of entries for which the block which is true
<FromGitter> <Blacksmoke16> @girng
<FromGitter> <girng> @Blacksmoke16 @asterite thanks. i'll use min_by much cleaner
<FromGitter> <Blacksmoke16> indeed
<FromGitter> <girng> @Blacksmoke16 understood. so only certain methods can have a return value (.select compared to .each). using .each with a return value makes no sense then?
<FromGitter> <Blacksmoke16> im pretty sure bew explained to you that .each returns nil
<FromGitter> <Blacksmoke16> a while back
<FromGitter> <girng> yea, i get the block and method part confused
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/0.24.2/Indexable.html#each%28%26block%29-instance-method
<FromGitter> <Blacksmoke16> the api docs are your friend here
<FromGitter> <girng> yeah i searched "sort" on hash api page
<FromGitter> <girng> couldn't find any matches so i post oin gitter
<FromGitter> <Blacksmoke16> :p
<FromGitter> <girng> this returns something?
<FromGitter> <girng> `Returns an Iterator for the elements of self.`
<FromGitter> <girng> wat
<FromGitter> <Blacksmoke16> returns an Iterator
<FromGitter> <girng> so each doesn't return nil
<FromGitter> <girng> it returns iterator
<FromGitter> <bew> each with a block returns nil
<FromGitter> <Blacksmoke16> ^
<FromGitter> <bew> each without a block returns an iterator
<FromGitter> <girng> ooo
<FromGitter> <girng> well, i want to use select now
<FromGitter> <girng> instead of each lol
<FromGitter> <girng> bcz if select, i can return something if iwant to
<FromGitter> <girng> more fair imo
<FromGitter> <bew> `@girng.brain.unlock`
<FromGitter> <Blacksmoke16> xD
<FromGitter> <Blacksmoke16> what you trying to do exactly?
<FromGitter> <bew> @girng it depends on the usecase! Note that `Enumerable#select` returns an Array, but `Iterator#select` returns an `Iterator`
<FromGitter> <girng> yeah. true. just saying i fi would ahve used .select instead of .each when i was trying to figure it out i would have found the solution already lol
<FromGitter> <girng> cuase it would have returned it to `find_first`
<FromGitter> <Blacksmoke16> mhm
<FromGitter> <Blacksmoke16> you could have got your .each to work by doing like
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/40fu
<FromGitter> <girng> WTF
<FromGitter> <girng> how does that work
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/40fv
<FromGitter> <Blacksmoke16> a bit cleaner
<FromGitter> <Blacksmoke16> `break can also take a parameter which will then be the value that gets returned:`
<FromGitter> <girng> `each with a block returns nil` && `each without a block returns an iterator`
<FromGitter> <Blacksmoke16> its not the .each that is returning the value, its the `break` keyword
<FromGitter> <girng> LOL
<FromGitter> <Blacksmoke16> which breaks out of the .each loop and returns the value you give it
<FromGitter> <girng> ....... so each can return the value
<FromGitter> <girng> by using a break
<FromGitter> <girng> if i got that right
<FromGitter> <girng> ok so, what's the difference between select and each. you don't have to use `break` with select? lol
<FromGitter> <Blacksmoke16> sorry kind of out of order but basic select just wraps reject, which wraps each_with_object that wraps each
<FromGitter> <Blacksmoke16> i.e. you could recreate what select does using .each but select provides a shortcut to do it
<FromGitter> <girng> .each = faster then?
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <girng> well, since ur example uses `each` with a break and returns the value im still going to use .each then
<FromGitter> <girng> i can just do your trick
<FromGitter> <girng> if i need to "return" something
<FromGitter> <Blacksmoke16> or just use a .select and have it much more readable
<FromGitter> <girng> well, i think the each with break is more readable cause i know what's it doing cuz we discussed it more :D
<FromGitter> <Blacksmoke16> oh boy
<FromGitter> <girng> and plus whenever i think of enumerating over something, `each` comes to mine a lot more fluid than `selecting something`
<FromGitter> <girng> but tht's just my personal preference :D
<FromGitter> <Blacksmoke16> .map is also quite powerful
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/40g2
<FromGitter> <girng> in any event. what i'm doing is a https://en.wikipedia.org/wiki/Round-robin_scheduling of the game servers which have the lowest load. when a player goes to create a game, the master servers will use the `min_by` method and get the first server that has the lowest amount of player. and that will be the next server the next player will use for their game instance
<FromGitter> <Blacksmoke16> and could have used `.min` vs sorting the array and selecting first value
<FromGitter> <girng> it's really nice anyways so i appreciate the help i think it'll work good.
<FromGitter> <Blacksmoke16> or `temp_array.first`
<FromGitter> <Blacksmoke16> bit more readable
<FromGitter> <Blacksmoke16> but imo id prefer readability over speed (at least in regards to using .select vs .each)
<FromGitter> <girng> that's interesting the map and min
<FromGitter> <girng> much more cleaner than my temp_array = [] of Int32 and temp_array << rofl
<FromGitter> <Blacksmoke16> mhm ;)
<FromGitter> <girng> just a simple 1 liner with &.
<FromGitter> <girng> nice one
<FromGitter> <girng> i still can't get that &. stuff engrained in my head lol
<FromGitter> <girng> i always resort to writing out the blocks 😢
<FromGitter> <Blacksmoke16> you'll get there
<FromGitter> <girng> i can't help it xD
<FromGitter> <girng> ` ⏎ p game_servers.values.map &.online_count`especially cuz this is valid
<FromGitter> <Blacksmoke16> im not a super big fan of no ()
<FromGitter> <girng> parenthesis are not required. but if it's used with parenethesis, it's easier to rad actually
<FromGitter> <girng> for me
<FromGitter> <Blacksmoke16> yea
<FromGitter> <girng> if using the &. not globally
<FromGitter> <girng> some methods i don't ike using parenthesis hahaha
<FromGitter> <girng> but when &. is involved, feels like parenthesis are needed :O
<FromGitter> <girng> ``` spawn do ⏎ loop do ⏎ sleep 0.067.seconds ⏎ end ⏎ end``` ⏎ ⏎ Game loop time. each fiber (game instance) gonna be 15hz tick rate 1/15 = 0.067. 6players per fiber. each cheap $5.00 vps will prob house 100 players. which will be around 16 games. that'sgoing to be a total of 250 iteration per second. crystal should handle that quite well right or is too much?
<FromGitter> <Blacksmoke16> guess you'll find out
<FromGitter> <girng> ahaah
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
<FromGitter> <faustinoaq> Oh, yeah another feature for scry 🎉
<FromGitter> <Blacksmoke16> neat
<FromGitter> <Blacksmoke16> was looking on adding expand on Enumerable `first` and `first?` by adding more options
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5aee6ee6db299d4004d53533]
<FromGitter> <Blacksmoke16> will build out methods out to tenth
<FromGitter> <bew> what if I want eleven?
<FromGitter> <Blacksmoke16> well as of now it only goes out to first so yea :p
<FromGitter> <Blacksmoke16> have to stop somewhere, this could literally go on forever lol
<FromGitter> <bew> I think first/last are way more common, and as you say there is no limit, so let's stop at first
<FromGitter> <Blacksmoke16> probably true
<FromGitter> <Blacksmoke16> just that ⏎ ⏎ ```arr.first looks real good ⏎ then you have to do like arr[1] ⏎ ...``` [https://gitter.im/crystal-lang/crystal?at=5aee706153ceca3604b5ab5b]
<FromGitter> <bew> I almost never type that myself, do you have an example?
<FromGitter> <Blacksmoke16> not off top of my head
<FromGitter> <girng> https://github.com/SuperPaintman/ulid is this the only guid like shard?
<FromGitter> <bew> and if you're accessing specific array element a lot maybe it should not be an array ? @Blacksmoke16
<FromGitter> <Blacksmoke16> :shrug: was more so just `see if i could` than to solve a specific use case
<FromGitter> <bew> then yes you can :)
<FromGitter> <Blacksmoke16> either way is pretty slick solution, macros ftw
<FromGitter> <bew> you could also write your methods as `def {{key.id}}; self[{{index}}]; end` it' faster & shorter
<FromGitter> <Blacksmoke16> i think i tried that but was an issue... sec
<FromGitter> <girng> can i have a fiber running inside a class?
<FromGitter> <Blacksmoke16> yea it errors out
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5aee719497e5506e049e8058]
<FromGitter> <bew> of yeah, that works only if the type is Indexable
<FromGitter> <Blacksmoke16> mhm
<FromGitter> <bew> so even doing [1] wouldn't work
<FromGitter> <Blacksmoke16> really the issue i just came across was like consistency, like can do `.first` on some things but then have to do [0] on others or char_at on others
<FromGitter> <bew> for consistency let's keep only first, because otherwise we'll never finish ^^
<FromGitter> <bew> and yes
<FromGitter> <bew> the way to access to element can different for different types
<FromGitter> <Blacksmoke16> not a major issue just a bit annoying sometimes
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Client Quit]
Yxhuvud has joined #crystal-lang
<FromGitter> <bew> g++ doesn't want my special crystal-like C++ syntax, that's weird 😛 it's hard to write C++ now that my mind is in crystal mode...
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
<FromGitter> <girng> WOW, this redis shard is freaking amazing
<FromGitter> <girng> synchronous redis commands.. = im in heaven
<FromGitter> <girng> crystal docs system needs their search fixed
<FromGitter> <girng> for example, this isn't just the redis docs, but it happens on the main docs too: http://stefanwille.github.io/crystal-redis/doc/Redis/Commands.html ⏎ ⏎ 1) do CTRL+F and search for `hmset`, you'll see it get highlighted. ⏎ 2) now go to the top left search bar, type in `hmset`, it returns no results [https://gitter.im/crystal-lang/crystal?at=5aee8e2a1eddba3d04d6cdee]
<FromGitter> <bew> because the search bar searches types, not methods
<FromGitter> <bew> thus master searches method also
<FromGitter> <girng> it needs to search all
<FromGitter> <bew> then use crystal master version
<FromGitter> <girng> it was fixed?
<FromGitter> <bew> 'fixed' it was not a bug ^^
<FromGitter> <bew> but yeah the search now search types & methods
<FromGitter> <girng> nice
<FromGitter> <girng> how do we get the other shard contributors who using old docs
<FromGitter> <girng> to update theirs?
<FromGitter> <girng> make issue on github and ask nicely?
<FromGitter> <bew> yeah you can do that, but they'll maybe say they'll wait for the next crystal release
<FromGitter> <girng> ok well i'll just wait for that too then. they prob dont' want to be bothered
<FromGitter> <girng> :D
<FromGitter> <bew> you can always clone their repo and generate the docs yourself with everything
<FromGitter> <girng> true. im too lazy to do that i'll prob search their github repo LOL
notdaniel has joined #crystal-lang
pabs has quit [Ping timeout: 240 seconds]
pabs has joined #crystal-lang
<FromGitter> <girng> Obligatory video (https://www.youtube.com/watch?v=fWNaR-rxAic) :D
<FromGitter> <girng> https://play.crystal-lang.org/#/r/40hq is this the correct way to do map the results from a redis.hgetall to a correct json?
<FromGitter> <girng> aww, no it's not the key/values are not consistent
<FromGitter> <girng> If you look here (https://i.gyazo.com/b842d9ea73277f1313d43c5f68c4d509.png), you can see what it returns
<FromGitter> <bew> for your original example, you can use `Enumerable#each_slice` to help you (https://play.crystal-lang.org/#/r/40i1)
<FromGitter> <girng> @bew very cool,
<FromGitter> <girng> @bew thx, working now =]
<FromGitter> <girng> i go bed. work on redis stuff tomorrow too! very excited, loving the redis shard. ttyl all gn thanks for support
That_Guy_Anon has joined #crystal-lang
notdaniel has quit [Remote host closed the connection]
notdaniel has joined #crystal-lang
<FromGitter> <bararchy> Does Crystal has a shard with logrotate support ?
hightower2 has quit [Ping timeout: 248 seconds]
<oprypin> bararchy, why do you care about that?
<FromGitter> <bararchy> well, I want to configure a log rotation system to my crystal logfile, I can use logrotate, but I know that Ruby has an option to decide max log file size and how many versions back to save
<oprypin> bararchy, i dont know if you've heard but there's this thing called systemd
<FromGitter> <bararchy> Is there? never heard of it ;)
<oprypin> i have this irc bot running for years just printing every message into stdout and systemd stores the logs "somehow", i dont care how
<FromGitter> <bararchy> so just log to stdout while systemd send it;s to journal
<FromGitter> <bararchy> hm...
<FromGitter> <bararchy> well, it's a good idea to be honset
<FromGitter> <bararchy> do you know how long back is this log handled
<FromGitter> <bararchy> nah, I'll just go read about it
<oprypin> however you configure it, for me seems like for ever
<FromGitter> <bararchy> thanks oprypin, sometime you sarcasm is helpful ;)
<FromGitter> <bararchy> so ⏎ ⏎ ```[Journal] ⏎ Storage=persistent ⏎ ``` [https://gitter.im/crystal-lang/crystal?at=5aeebb696f9af87e0447a83c]
<FromGitter> <bararchy> else it delete the log every reboot
<oprypin> bararchy, i have the default of "auto" and it works as persistent, for all intents and purposes
<FromGitter> <bararchy> interesting, I'll try it out, might save me a big head pain
<oprypin> bararchy, i have non-defaults only in the options "MaxRetentionSec" and "SystemMaxUse", so maybe these are more relevant
<oprypin> these are all global settings though. i don't know if there are per-unit settings, i would sure hope so
<FromGitter> <bararchy> There are also some relevant flags in ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5aeebd7ff2d2d5370468404c]
<FromGitter> <bararchy> to handle space etc..
<FromGitter> <bararchy> I'll do my homework, but it indeed seems to be a good solution
DTZUZO has quit [Ping timeout: 264 seconds]
DTZUZO has joined #crystal-lang
notdaniel_ has joined #crystal-lang
notdaniel has quit [Ping timeout: 260 seconds]
notdaniel_ is now known as notdaniel
<FromGitter> <bararchy> lol now it looks wierd, I have systemd "syslog" formatting, and the string is a syslog-formatted message also
alex`` has quit [Ping timeout: 268 seconds]
alex`` has joined #crystal-lang
Philpax has joined #crystal-lang
notdaniel has quit [Quit: notdaniel]
notdaniel has joined #crystal-lang
Philpax_ has joined #crystal-lang
Philpax has quit [Ping timeout: 240 seconds]
notdaniel has quit [Quit: notdaniel]
rohitpaulk has joined #crystal-lang
<FromGitter> <bararchy> wow! https://github.com/pytorch/glow
<FromGitter> <j8r> @oprypin define `[Service] ⏎ StandardOutput=` as https://www.freedesktop.org/software/systemd/man/systemd.exec.html#
<oprypin> sorry what?
<FromGitter> <j8r> for you systemd problem of logging to journal?
<oprypin> there is no problem
<FromGitter> <j8r> oh ok, I didn't follow everything.
<FromGitter> <j8r> I'v seen ⏎ ⏎ > i have this irc bot running for years just printing every message into stdout and systemd stores the logs "somehow", i dont care how
andersh has quit []
andersh has joined #crystal-lang
That_Guy_Anon has quit [Remote host closed the connection]
jokke has quit [Ping timeout: 260 seconds]
<FromGitter> <bararchy> If any of you guys is interested in a small and generalized example of Q-Learning in Crystal @ArtLinkov just added a nice example at https://github.com/ArtLinkov/qlearning
<FromGitter> <bararchy> it's a small fun game that teach an agent to play a map with reward and punishment
<FromGitter> <ArtLinkov> Thanks @bararchy :)
<FromGitter> <bew> do you have a simple description of what qlearning is?
<FromGitter> <j8r> Just played, like it - but what's the goal of the game?
rohitpaulk has quit [Ping timeout: 260 seconds]
<FromGitter> <ArtLinkov> Q-learning is a method for an agent to "learn" the environment by exploration, without knowing the layout in advance. So the agent is exploring and has a memory of all the locations he was in previously. The goal in this game is to reach the reward (@), so the agent is running around the map until it finds it. At first, it is rather random, but after it finds the reward for the first time, it starts to update
<FromGitter> ... its "memory" so that it can always find the optimal path towards it. Same goes for the punishment (x), it learns to avoid it
jokke has joined #crystal-lang
<FromGitter> <bew> pretty cool
<FromGitter> <bararchy> It is :)
<FromGitter> <ArtLinkov> Yeah, it's quite a powerful algorithm because its quite cheap resource-wise
<FromGitter> <bararchy> @bew If you are interested in seeing more examples, here is a Google mind Q-Learning playing ATARI => https://www.youtube.com/watch?v=V1eYniJ0Rnk&vl=en ⏎ Overall it's the same logic just on different problems
<FromGitter> <ArtLinkov> @bararchy this is deep q-learning :) ⏎ But yeah the basic concept is the same
faustinoaq has quit [Ping timeout: 248 seconds]
<FromGitter> <bajro17> Hi
<FromGitter> <bajro17> Do you have any package for http2
<FromGitter> <bararchy> @bajro17 https://github.com/ysbaddaden/http2
DTZUZO has quit [Read error: Connection reset by peer]
DTZUZO has joined #crystal-lang
<FromGitter> <bajro17> Thank you so much I will check it @bararchy . They dont have default?
<FromGitter> <bew> no, not yet
<FromGitter> <bararchy> I guess @ysbaddaden shard is the closest to a complete solution, maybe when it's ready it will be integrated into the STD
<FromGitter> <bew> Now I can goto sleep; #6069 😄
<DeBot> https://github.com/crystal-lang/crystal/issues/6069 ([RFC] Always return a special reference for inlined value type instead of copy)
<FromGitter> <bararchy> @bew nice!
<FromGitter> <bararchy> I'll go over it
<FromGitter> <bew> thanks! ;)
<FromGitter> <bew> I got the idea 5 hours ago, so there are not *a lot* of thought, but I like it so far, I can't wait feedback :P
<FromGitter> <bararchy> @bew
<FromGitter> <bew> ?
<FromGitter> <bararchy> basiclly this means all Tuple + Struct are always on the stack until used, even when "stored" in an array or class ?
<FromGitter> <bararchy> until called i mean
<FromGitter> <bew> no, (named)tuple, structs & other value types are on the stack by default, it's when they are embedded in a type (e.g: the `Container` class in the example, or in an array of structs) that the struct is no longer on the stack, but copied in-place in the memory area of the container
faustinoaq has joined #crystal-lang
Philpax_ has quit [Ping timeout: 260 seconds]
<FromGitter> <hmans> I love Crystal for many things, but one of them is the `spec` module... https://github.com/hmans/crankypants/blob/crappylicious/spec/crappy_spec.cr (WIP)
<FromGitter> <hmans> Big fan of RSpec, so I'm happy Crystal is mirroring the DSL to some extent.
<FromGitter> <j8r> @hmans would be better to divide them in `it`s https://github.com/hmans/crankypants/blob/crappylicious/spec/crappy_spec.cr#L38
<FromGitter> <j8r> e.g. `it routes /`, `it routes /home`...
<FromGitter> <hmans> @j8r I know. Focus so far was on building that TestRequest scaffolding.
<FromGitter> <hmans> Actually, let me clarify, since I don't agree fully.
<Yxhuvud> there are some stuff I'm really missing from rspec, like the ability to define inline methods scoped to a describe scope.
<Yxhuvud> *spec. rspec has it of course.
<FromGitter> <hmans> In this example, I want to prove that Crappy's routing works, and that's what I'm doing. It's different from proving that /foo returns "Foo!".
<FromGitter> <hmans> The "any example should only ever run one expectation" school of thinking is a bit shortsighted IMO.
<FromGitter> <hmans> (Hi, I give software testing workshops for a living :b)
<FromGitter> <j8r> Yes but I one route work on others not, would be harder to debug which one is KO
<FromGitter> <hmans> @yxhuvud Yes, I noticed that internally, Crystal's spec seems to tick quite differently from RSpec. Apparently, examples don't run on instances of anything? I was sort of expecting `describe` et al were macros that create classes (I haven't looked at the source yet)
<FromGitter> <hmans> I tried to implement a `let` macro and were stopped by the compiler because I can't create new `def`s in whatever context `describe` ends up setting up. Need to dive deeper at some point.
<Yxhuvud> tbh I'd rather have methods than let, especially as methods give me everything I want of let :)
<FromGitter> <hmans> Well, you can't write methods within a `describe` block, either, and when you do it outside, you lose the nice cascading nature of RSpec's `let`s.
<FromGitter> <hmans> (Ignoring the fact that `let` does solid memoization out of the box that you would have to implement yourself over... and... over... again)
<FromGitter> <hmans> (which would be hard to do because you don't even have an instance of anything to set instance variables on.)
<FromGitter> <hmans> It's good that Crystal has `spec`, but looking at Crystal's own spec suite, it seems it's using it mostly like one would use *Unit, MiniTest et al, just with things named a little differently
<FromGitter> <hmans> I may be missing something about how Crystal handles blocks... but is there a saner pattern for what I'm doing in this line? https://github.com/hmans/crankypants/blob/crappylicious/src/crappy.cr#L97
<FromGitter> <hmans> (ie. I want to forward the block, but I want to do it with any block argument signature)
<FromGitter> <j8r> `.try` or `.tap`
<FromGitter> <j8r> to yields `self`
<FromGitter> <asterite> @hmans no, that's the way it works right now
<FromGitter> <hmans> Thanks @asterite
<txdv> the description of that project is A+
<FromGitter> <hmans> Yes. I like to be exact.
<FromGitter> <j8r> @girng why using Redis? There is RocksDB, an embedded KV https://github.com/maiha/rocksdb.cr
<FromGitter> <j8r> But Redis is still useful if you have different languages
<FromGitter> <j8r> There is also LevelDB
That_Guy_Anon has joined #crystal-lang
avdi has quit []
avdi has joined #crystal-lang
OvermindDL1 has quit []
OvermindDL1 has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter> <girng> @j8r not sure. i heard redis is very fast and trusted in the industry. i used it with nodejs for in-memory database storage and horizontal scale w/ pub sub too. i take a look at rocksDB though, thank you
<FromGitter> <girng> good morning btw.
manveru has quit []
manveru has joined #crystal-lang
<FromGitter> <hmans> @girng \o/
danzilio has quit []
danzilio has joined #crystal-lang
DTZUZU has quit [Quit: WeeChat 1.9]
DTZUZU has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <girng> =]
WA9ACE has quit []
WA9ACE has joined #crystal-lang
<FromGitter> <girng> `code block` if value == true
<FromGitter> <girng> is it possible to have multiple code blocks in there and still use 1 `if value === true`?
<FromGitter> <Blacksmoke16> hm?
<FromGitter> <girng> for example
<FromGitter> <girng> db.query("QUERY"), db.query("QUERYHERE") if variable == true
<FromGitter> <girng> is something like that possible in crystal?
<FromGitter> <girng> yah, but is itpossible for multiple code blocks
<FromGitter> <girng> before the inline if statement
<FromGitter> <girng> ..er should i say, execution
<FromGitter> <hmans> @girng https://play.crystal-lang.org/#/r/40mt
<FromGitter> <hmans> That's as good as it gets. It's exceptionally bad style of course. But you asked for it!
Yxhuvud has quit [Remote host closed the connection]
<FromGitter> <girng> @hmans interesting indeed lol
<FromGitter> <girng> thanks for example =]
Yxhuvud has joined #crystal-lang
<FromGitter> <bew> You can use parentheses https://play.crystal-lang.org/#/r/40mx
<FromGitter> <girng> oh wow
<FromGitter> <hmans> Oh god
<FromGitter> <girng> that's actually not too bad
<FromGitter> <bew> But I would not recommend it, 'better to a proper if with a multiline body
<FromGitter> <girng> i would have never thought semicolons would make it work haahhaa
<FromGitter> <girng> OH WOW
<FromGitter> <girng> commas???
<FromGitter> <bew> You should read the Crystal parser, you'll learn a lot
<FromGitter> <bew> Yeah that too I forgot about it
<FromGitter> <girng> hell yeah
<FromGitter> <girng> freaking awesome
<FromGitter> <bew> @girng it's like in C actually (another dark syntax! \o/)
<FromGitter> <hmans> Well, note that it printed "bar" first.
<FromGitter> <hmans> The second puts is an argument to the first puts.
<FromGitter> <bew> It'll return the last expression in the parentheses
<FromGitter> <hmans> So please do not ever follow that example with the commas.
<FromGitter> <girng> @hmans oh good catch didn't even notice that lol
<FromGitter> <hmans> (It works fine when you replace that comma with a semicolon, though. Good enough.)
<FromGitter> <girng> i wonder why it does that with commas, since puts foo was first
<FromGitter> <Blacksmoke16> `The second puts is an argument to the first puts.`
<FromGitter> <girng> oh argument
<FromGitter> <girng> yeah, got it
<FromGitter> <girng> oh god yeah, im not gonna do that
<FromGitter> <girng> coool to know i was just curious thinking about syntax thats all
<FromGitter> <girng> im having an issue with socket.remote_address however ⏎ my game instance server makes a connection to my master server. when it does, it sends a key to authenticate itself as master server. ⏎ then my master servers stores that connections socket.remote_address, in a hash. ⏎ ⏎ except, t he socket.remote_address is returning `127.0.0.1:57488`, but the game instance server is started on
<FromGitter> ... `GameServer.new("0.0.0.0", 9301)` [https://gitter.im/crystal-lang/crystal?at=5aef549f59a0578004ac4358]
<FromGitter> <valamorgon> the other day we discussed here for multiple table select with granite
<FromGitter> <valamorgon> I came accross sqlalchemy syntax for that
<FromGitter> <valamorgon> db.query(Member.id, Post.id, Member.JoinDate).filter(Member.Type=="assistant").all()
<FromGitter> <valamorgon> I think it looks cool
<FromGitter> <valamorgon> just a thought
<faustinoaq> @girng Hehe, Do you want to see something crazy in crystal? ;-)
<FromGitter> <hmans> A socket connection has two ends, and maybe 127.0.0.1:57488 is the connecting client's side of it ;-)
<FromGitter> <girng> yeah but im calling remote_address
<FromGitter> <girng> i want the ip, port oft he connection how do i get that
snsei has joined #crystal-lang
<FromGitter> <hmans> I'm not sure what you're trying to do. 127.0.0.1:57488 looks like a legit `remote_address` of something that connected to you.
That_Guy_Anon has quit [Quit: Leaving]
<faustinoaq> @girng see: https://carc.in/#/r/2sv6
<FromGitter> <girng> but 127.0.0.1:57488 isn't the server that i created, i'm just using that crystal game instance to connect to master server to create a tcp connection. the master server should know the real ip/port of the game instance server
<FromGitter> <hmans> Is all of that happening on your local machine?
<FromGitter> <girng> i created the server on 0.0.0.0:9301
<FromGitter> <girng> yah
<FromGitter> <girng> but im making a tcp connection not waiting for master server. maybe that's why?
<FromGitter> <hmans> When your master sees your instance server's incoming connection as 127.0.0.1:57488, that's exactly what it is. It means the connecting client is on interface 127.0.0.1 and port 57488.
<FromGitter> <girng> but that's not where the game instance server is running so how the hell is that possible
<FromGitter> <girng> it's running on 0.0.0.0:9301
<FromGitter> <girng> all i want to get is the IP and port
rohitpaulk has joined #crystal-lang
<FromGitter> <hmans> Any outgoing TCP connection is assigned a random-ish port number, and that's what the server sees when he inspects the client's `remote_address`.
<FromGitter> <mjago> @sdogruyol Thanks for the compiments about Sonicri ~ the idea is to get it onto a raspberry pi with touch screen control, but not there yet 😉
<FromGitter> <girng> yes i understand but it should be possible to still get the server it's on. not just the ephemeral port/ip
<FromGitter> <girng> so i have to send the ip:port of the game instance through tcp, to the master server?
<FromGitter> <girng> but shouldn't the master server already know about my ip and port. makes no sense
<FromGitter> <girng> i mean the TCP connection has been ESTABLISHED
<FromGitter> <bew> Huh no, that's 2 different things the game server listening to some port and that same gameserver connecting to a master server. These 2 connections are unrelated
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <girng> how are those unrelated
<FromGitter> <bew> So yeah you need to send the data if you need it
<FromGitter> <girng> the game server is connecting tot he master server
<FromGitter> <girng> the game server should know the ip/port of that connection
<FromGitter> <girng> if they established a connection (which i already did)
<FromGitter> <bew> But you have the gameserver listening to the port 9301 also, right?
<FromGitter> <girng> yeah
<FromGitter> <bew> Then you have 2 separate / related things
<FromGitter> <bew> 1) The gs listening
<FromGitter> <bew> 1) The gs connection to the master
<FromGitter> <bew> Grr 2.
snsei has quit [Remote host closed the connection]
<FromGitter> <bew> The connection to master is not linked in any way to the gs listening
snsei has joined #crystal-lang
<FromGitter> <bew> *unrelated
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
<FromGitter> <girng> makes sense
snsei has quit [Remote host closed the connection]
<FromGitter> <girng> however, if i start the connection on a vps, and block all ports except for 9301
snsei has joined #crystal-lang
<FromGitter> <girng> how in the hell am i supposed to connect to the master SERVER
<FromGitter> <girng> from the game server...
snsei has quit [Remote host closed the connection]
<FromGitter> <bew> The gs could listen on many ports, it doesn't matter
<FromGitter> <bew> Ah
snsei has joined #crystal-lang
<FromGitter> <bew> But they are on the same machine right?
snsei has quit [Remote host closed the connection]
<FromGitter> <girng> now,but not when i buy the VPS
snsei has joined #crystal-lang
<FromGitter> <bew> Huh why not? You're buying multiple vps and connecting them together?
<FromGitter> <girng> yeah i buy 1 vps for master server, block all ports except 9300. then buy 2 smaller vps for game instance servers, put 1 west/east USA
snsei_ has joined #crystal-lang
<FromGitter> <girng> those game instance server connect to master server an authenticate themselves
<FromGitter> <girng> and those game instance servers, only allow 9301 port for other players to connect
<FromGitter> <bew> That's ok
<FromGitter> <girng> so how do i dynamically take care of all this `127.0.0.1:57488` bologna is beyond me
<FromGitter> <girng> when the port # changes..
<FromGitter> <girng> randomly
<FromGitter> <girng> lmfao.
<FromGitter> <bew> Make your gs listen to that port (for incoming request)
<FromGitter> <bew> When you connect to the master server it's an outgoing request, so it should work normally
<FromGitter> <girng> different than local machine (what i'm dealing with now)?
<FromGitter> <bew> It seems like you're only restricted to 1 port for incoming requests
<FromGitter> <bew> But you shouldn't be restricted for outgoing requests (from your server to somewhere else)
<FromGitter> <girng> yeah, correct
<FromGitter> <girng> just incoming ports i close all, and open certain ones
snsei has quit [Ping timeout: 276 seconds]
<FromGitter> <drum445> When hosting a crystal app for production (it's using kemal) can I use it similar to go, that is compile to a binary and run on a port on my server, or do I need to put it behind Nginx?
<FromGitter> <drum445> Would love to confirm that I can just run ./app on my server
<FromGitter> <bew> So there's no problem, you can make an outgoing connection to your master server from the gs @girng
<FromGitter> <bew> And communicate with it (send it the port you're listening on for example)
<FromGitter> <girng> @bew well, yes but i need the master server to know which ip port that connection is (when the gs makes the connection). ⏎ ⏎ should i just send the ip:port in a tcp message when i authenticate??
<FromGitter> <bew> You probably can't send the ip, but you can send the port
<FromGitter> <bew> And the master will find the ip in remote_address
<FromGitter> <girng> ok
<FromGitter> <girng> yeah that's what i was thinking
<FromGitter> <bew> @girng why does it need to know that actually?
<FromGitter> <bew> To redirect users that first connect to the master, to their nearest gs? (or sth like that?)
<FromGitter> <girng> my master server stores the game_servers in a hash, and when a user creates a game, master server dose `min_by` and finds least active server to put the player. then the master server sends that ip/port to the connected player so they can join that instance
<FromGitter> <girng> yeah what you said, basically
<FromGitter> <bew> @drum445 I think you can just use it directly
<FromGitter> <drum445> @bew cheers sir, I've been running it directly for a week or so and haven't seen any issues. Was just curious to see if this was ok
<FromGitter> <girng> i am not sure about authentication though. i want to generate a GUID for the server transfer
<FromGitter> <bew> I never deployed anything myself in production actually, but I think nginx would be a good idea to have some kind of protection, or more specific regulation of the traffic, etc
<FromGitter> <bew> @drum445 ^
<FromGitter> <girng> yes nginx is great for reverse proxy
<FromGitter> <girng> and the rate limiting and stuff is perfect to put infront of kemal
<FromGitter> <drum445> any tutorials on how to do that?
<FromGitter> <drum445> I like the simplicity of running the binary on the server
<FromGitter> <drum445> ssl is important mind
<FromGitter> <girng> basically https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/ start kemal on a secure internal port, like `81`. then just pass it through the `proxy_pass`.
<FromGitter> <drum445> thanks @girng I shall have to look into that
<FromGitter> <drum445> While I do I'll keep it running as a binary :)
<FromGitter> <bew> That's a cool link, ty!
<FromGitter> <drum445> Go and Crystal are the only languages I will use now because of how nice the compile to one binary is
<FromGitter> <bew> Hehe :) what do you use Go for?
<FromGitter> <drum445> web apis and anything that deals with large data
<FromGitter> <drum445> I do miss my class based programming though
<FromGitter> <drum445> that's where Crystal comes in
<FromGitter> <girng> https://crystal-lang.org/api/0.24.2/UUID.html any examples how to use this?
<FromGitter> <drum445> ```require "uuid" ⏎ UUID.random.to_s``` [https://gitter.im/crystal-lang/crystal?at=5aef601e53ceca3604b7cae7]
<FromGitter> <drum445> gives me a uuid, I use for all my objects
<FromGitter> <girng> awesome, ty =]
<FromGitter> <girng> https://paste.ee/p/0pfPA
<FromGitter> <girng> gg header file right there 😂
<FromGitter> <drum445> ha
<FromGitter> <victor95pc> hi how you guys debug yours apps?
<FromGitter> <victor95pc> I using VS code and I installed LLDB extension to debug crystal, but the debugg console dont show a lot of things
<FromGitter> <drum445> ```puts "we got here"``` ⏎ debugging is for the weak ;)
<FromGitter> <victor95pc> lol
<FromGitter> <victor95pc> dont think so, I know its almost impossible to add a binding.pry hehe
<FromGitter> <victor95pc> I only have a Javascript(ES6) and Ruby background
<FromGitter> <victor95pc> and in both of them its kind easy to debug and It saved a lot of time
<FromGitter> <bew> Yeah they both (js & ruby) are interpreted so it's very easy to make a debugger
<FromGitter> <victor95pc> yeap, but you only use puts to debug?
<FromGitter> <bew> I rely a lot on types to make sure compiler can tell me if I miss something, or mess up with the types
<FromGitter> <bew> Then yeah pp (pretty print) in specific locations
<FromGitter> <bew> And debug things part by part to find a problem
<FromGitter> <bew> And unit tests (very important!)
<FromGitter> <victor95pc> I think I need to rely even more in unit test
<FromGitter> <victor95pc> thx helped a lot
<FromGitter> <bew> You're welcome :)
oprypin has quit [Remote host closed the connection]
oprypin has joined #crystal-lang
<FromGitter> <drum445> do you guts use debuggers and heavy IDEs for your other languages?
<FromGitter> <drum445> I usually just use sublime/vim for everything
FromGitter has quit [Remote host closed the connection]
oprypin has quit [Quit: Bye]
FromGitter has joined #crystal-lang
oprypin has joined #crystal-lang
<FromGitter> <Blacksmoke16> are there any docs on what the `targets` portion of shards.yml is used for
<FromGitter> <Blacksmoke16> cheers
rohitpaulk has joined #crystal-lang
<FromGitter> <Blacksmoke16> neat
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <faustinoaq> Code outline 😄 🎉 https://github.com/crystal-lang-tools/scry/pull/114
RX14 has quit [Ping timeout: 260 seconds]
BlaXpirit has joined #crystal-lang
RX14 has joined #crystal-lang
RX14 is now known as Guest21720
oprypin has quit [*.net *.split]
DTZUZO has quit [*.net *.split]
faustinoaq has quit [*.net *.split]
BlaXpirit is now known as oprypin
faustinoaq has joined #crystal-lang
DTZUZO has joined #crystal-lang
alex`` has quit [Quit: WeeChat 2.1]
<FromGitter> <girng> @faustinoaq damn that looks epic
<FromGitter> <girng> @faustinoaq i relly want to move to vscode now
<FromGitter> <girng> 410 to 470 karma, let's c how long it sticks
<FromGitter> <fridgerator> @faustinoaq is it easy to get that same set up running in vscode?
<FromGitter> <fridgerator> or is there some custom stuff going on there
<FromGitter> <fridgerator> I know you've done a ton of work with vscode plugins for crystal
<FromGitter> <faustinoaq> @fridgerator @girng Nop, nothing have been done on vscode-crystal-lang extension, this is just Scry, so this should work on other editors as well. ⏎ ⏎ I'm already testing it Sublime and Intellij-Idea as well 😉