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
oddp has quit [Quit: Quit]
deavmi has quit [Read error: Connection reset by peer]
chachasmooth has quit [Ping timeout: 240 seconds]
chachasmooth has joined #crystal-lang
chachasmooth has quit [Ping timeout: 245 seconds]
chachasmooth has joined #crystal-lang
<FromGitter> <naqvis> should be pretty straight-forward to implement IO for this use-case and use-case is quite valid to have a Rotating Fixed Size IO
<FromGitter> <naqvis> unlike `IO::Memory` which expands when needed, this implementation should be a fixed size and perform rotation when capacity reached
<FromGitter> <naqvis> was just thinking a scenario: ⏎ ⏎ ```io = RotatingIO.new(capacity: 3) ⏎ io << "hello" ⏎ pp io.gets_to_end``` ⏎ ⏎ what one should expect? ... [https://gitter.im/crystal-lang/crystal?at=6098ac4ff7e4221825c9affe]
deavmi has joined #crystal-lang
z_ has joined #crystal-lang
z_ is now known as Guest47369
Guest47369 has left #crystal-lang [#crystal-lang]
trepanger_ has joined #crystal-lang
_ht has joined #crystal-lang
<yxhuvud> depending on usecase, for the case when rotating isn't wanted but rather to block if not consumed, a pipe could be relevant.
<yxhuvud> as for what you'd get, it would be `llo`, as the implementation should keep track of where the start is.
hendursa1 has joined #crystal-lang
<FromGitter> <naqvis> > e.g. an `IO::Memory` that stores at most n bytes, removing the earlier ones ⏎ ⏎ my understanding of this sentence was FIFO, so with the presence of `hel`, adding two chars `lo` should remove `he`
hendursaga has quit [Ping timeout: 240 seconds]
<FromGitter> <naqvis> next addition of char should replace the 3rd char and continue from the start
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
alexherbo2 has joined #crystal-lang
<yxhuvud> naqvis: That would be how it would be stored, sure. But why would anyone want gets_to_end to not be position aware?
<FromGitter> <naqvis> it should be position aware, but i didn't include `io.rewind` in my contrived scenario :P
<yxhuvud> Right. It might be worth having separate writers and readers then. :)
<FromGitter> <naqvis> :P
HumanG33k has quit [Quit: Leaving]
HumanG33k has joined #crystal-lang
Nekka has quit [Ping timeout: 246 seconds]
Nekka has joined #crystal-lang
hendursa1 has quit [Ping timeout: 240 seconds]
hendursa1 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 268 seconds]
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Read error: Connection reset by peer]
alexherbo2 has joined #crystal-lang
<FromGitter> <cut3_gh0st_twitter> Hello everyone, I have a question that may not be related to Crystal Lang but I need help. I have made a small custom HTTP server written in Crystal, now I need to set it up on AWS EC2 instance and I need to get traffic to it. Does anyone here have a similar experience with this, they would love to share? Any links related to this topic would be appreciated. :D
<FromGitter> <Blacksmoke16> ☝️ May 9, 2021 11:45 PM (https://gitter.im/crystal-lang/crystal?at=6098ac4ff7e4221825c9affe) ⏎ ⏎ Yea `llo` given those are the three newest chars
<FromGitter> <Blacksmoke16> @cut3_gh0st_twitter via docker or just the raw server?
<FromGitter> <cut3_gh0st_twitter> raw server
<FromGitter> <Blacksmoke16> id probably use https://crystal-lang.org/2020/02/02/alpine-based-docker-images.html to build a static binary, copy it to the server, then should just be able to run it
<FromGitter> <Blacksmoke16> not including what needs done in AWS itself ofc tho
<FromGitter> <naqvis> i believe question was how to generate traffic to his hosted webserver
<FromGitter> <Blacksmoke16> prob would be resources related to running a Go server, should handle the AWS side of things id imagine
alexherbo2 has quit [Ping timeout: 268 seconds]
alexherbo2 has joined #crystal-lang
<FromGitter> <naqvis> @Blacksmoke16 for RotatingIO should you expect it to decline to overwrite once buffer is full and nothing has been read? or it should overwrite silently?
<FromGitter> <Blacksmoke16> maybe have it be configurable via a bool. overwrite silently or raise an exception
<FromGitter> <Blacksmoke16> but i imagine the latter would be the default. Like if you write more to it than is allowed, would really only keep the the last n
<FromGitter> <naqvis> hmm yeah, something like `RotatingIO(capacity = 64, overwrite = true)`
<FromGitter> <naqvis> something like https://en.wikipedia.org/wiki/Circular_buffer ?
<FromGitter> <Blacksmoke16> yea pretty much
<FromGitter> <Blacksmoke16> https://github.com/symfony/symfony/blob/5.x/src/Symfony/Component/Console/Output/TrimmedBufferOutput.php porting this and figured i could use an IO like this versus relying on string manipulation like they're diong
<FromGitter> <naqvis> yeah, seems a solid candidate for IO
<FromGitter> <naqvis> but symfony one is kinda read once write many
<FromGitter> <naqvis> as `fetch` is going to clearup the contents once read
<FromGitter> <naqvis> but `IO` behavior is different in Crystal, its read many write many
<FromGitter> <Blacksmoke16> true true
<FromGitter> <naqvis> so dp you already have the implementation?
<FromGitter> <naqvis> or i can see if i can come up with something :P
<FromGitter> <Blacksmoke16> i basically just copied it over 1:1 :shrug:
<FromGitter> <Blacksmoke16> to get something working
<FromGitter> <naqvis> problem solved 😄
<FromGitter> <Blacksmoke16> haha yea, figured i could optimize it later if needed. more so was just curious
alexherbo2 has quit [Quit: Ping timeout (120 seconds)]
alexherbo2 has joined #crystal-lang
<FromGitter> <naqvis> topic is definitely interesting and stdlib or ecosystem doesn't have any `CircularBuffer` and/or `CircularIO`
<FromGitter> <naqvis> so might be a good candidate for an implementation
<FromGitter> <Blacksmoke16> yea esp since it has sized and buffered
<FromGitter> <naqvis> yeah true
<FromGitter> <Blacksmoke16> well buffered mixin*
<FromGitter> <cut3_gh0st_twitter> @naqvis Yes you are right I need a way to generate traffic to my server.
alexherbo24 has joined #crystal-lang
<FromGitter> <Blacksmoke16> oh like for testing?
alexherbo2 has quit [Ping timeout: 246 seconds]
alexherbo24 is now known as alexherbo2
<FromGitter> <Blacksmoke16> and/or benchmarking?
<FromGitter> <cut3_gh0st_twitter> sort of, lets say
<FromGitter> <Blacksmoke16> https://github.com/wg/wrk comes to mind
<FromGitter> <cut3_gh0st_twitter> Okay thanks, but by generate I mean forward the real traffic to server
<FromGitter> <Blacksmoke16> oh
<FromGitter> <cut3_gh0st_twitter> it will have it's static IP
<FromGitter> <cut3_gh0st_twitter> just like I it works locally I need it to be on AWS
<FromGitter> <Blacksmoke16> i imagine there are plenty of resources on google about this, given its not a crystal specific thing
<FromGitter> <Blacksmoke16> sounds like you just need to forward ports 80/443 to the http server running on port 3000 or whatever
<FromGitter> <Blacksmoke16> iirc @jwoertink has some stuff running on ec2, maybe he has some thoughts on specific links or something
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 240 seconds]
f1reflyylmao is now known as f1refly
<FromGitter> <cut3_gh0st_twitter> Yeah, that is the reason why I said it's not so much Crystal related question. Thank you for your help @Blacksmoke16
<FromGitter> <Blacksmoke16> np
<FromGitter> <naqvis> @Blacksmoke16 re that CircularIO, suppose with overwrite mode: ⏎ ⏎ ```io = CircularIO.new(3) ⏎ io << "hello"``` ⏎ ⏎ though buffer is of size 3, but writer would have written 5 bytes and buffer would contain `lol`, so invoking a read, would you expect it to read how many times a write was made? or cap it to buf length? [https://gitter.im/crystal-lang/crystal?at=60996c8820d4f02631b36f99]
<FromGitter> <naqvis> Question i'm trying to pose is, as `write` is circular, so does the read would be
<FromGitter> <naqvis> don't know if i'm making any sense :P
<FromGitter> <jwoertink> Yup. I'm running on ElasticBeanstalk (EC2). @cut3_gh0st_twitter
<FromGitter> <jwoertink> Thanks for the mention @Blacksmoke16
<FromGitter> <jwoertink> I'm around on the Crystal Discord if y'all have any questions.
<FromGitter> <cut3_gh0st_twitter> @jwoertink I will hit you on Discord then, thank you
<FromGitter> <alex-kampa> Hello everyone! I have a question about reusing parts of a json data structure to construct a new data structure. What is the best/easiest way to do this?
<FromGitter> <alex-kampa> In Ruby I would simply do: ⏎ ⏎ json = JSON.parse(message.as(String)) ⏎ ⏎ response = { ... [https://gitter.im/crystal-lang/crystal?at=60998bd6963923553af5d5f1]
<FromGitter> <Blacksmoke16> deserialize the data into objects an work with those
<FromGitter> <Blacksmoke16> working with `JSON::Any` and/or a `Hash` like that isnt great
<FromGitter> <alex-kampa> @Blacksmoke16 the reason I'm asking is that I only need to check a single field of the received JSON object, and then return a large part of the json as-is. So was hoping I could avoid the deserialising / rebuilding / reconverting back to json by just using a json structure that is in fact already there.
<FromGitter> <Blacksmoke16> naw, you have a `String`, whether you deserialize it into an object via `.from_json` or `JSON::Any` via `JSON.parse`, it'll have to be parsed regardless
<FromGitter> <Blacksmoke16> you prob could get away with `JSON::Any` to avoid needing to define types for the whole structure but might be a bit painful
_ht has quit [Remote host closed the connection]
<FromGitter> <alex-kampa> Here's a very baffling one: ⏎ ⏎ itx0 = { ⏎ ⏎ ```"StateHash" => "", ⏎ "InternalTransactionReceipts" => [receipt0]``` ... [https://gitter.im/crystal-lang/crystal?at=6099b39a0845c416dcd6cfb3]
<FromGitter> <alex-kampa> But then: ⏎ ⏎ response["InternalTransactionReceipts"] << receipt0.clone
<FromGitter> <alex-kampa> Error: undefined method '<<' for String (compile-time type is (Array(Hash(String, Bool | Hash(String, Hash(String, Hash(String, String) | Int32) | String))) | String))
<FromGitter> <Daniel-Worrall> All values of a Hash have the same type
<FromGitter> <Daniel-Worrall> So the Values are either the typeof receipt0, or a String (from `"StateHash" => ""`)
<FromGitter> <Daniel-Worrall> Well, Array(receipt0)
<FromGitter> <alex-kampa> Hi @Daniel-Worrall yes so far so good. But response["InternalTransactionReceipts"] is clearly an Array, and not a String as the error message suggests
<FromGitter> <Daniel-Worrall> The error is saying you have not taken into consideration the case where the value could be a String.
<FromGitter> <Daniel-Worrall> The Hash value could be a string since you have a String as one of the values, so it is `Array(Foo) | String`
<FromGitter> <Daniel-Worrall> Of course, in runtime, it will never be a String, but that is not the case in Compile time
<FromGitter> <alex-kampa> So are you suggesting something like: if response["InternalTransactionReceipts"].is_a?(Array)
<FromGitter> <Blacksmoke16> working with hashes like this is a pita
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
<FromGitter> <Daniel-Worrall> You would have to assign it to a local variable to type restrict it
<FromGitter> <Daniel-Worrall> https://carc.in/#/r/b40o
<FromGitter> <alex-kampa> Hi @Daniel-Worrall thanks for your suggestion - your code snippet works but when applied to my data structure (again surprisingly) it does not. But I did learn something ... and have found a workaround in the meantime: constructing the Array first and only then plugging into the Hash.
<FromGitter> <alex-kampa> > working with hashes like this is a pity ⏎ ⏎ Hi @Blacksmoke16 maybe not elegant but explicit. I like seeing my data structures :-)
<FromGitter> <Blacksmoke16> less explicit than using actual objects where you'd know the type of each property and suchh