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
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
kiwiroy has quit [Ping timeout: 252 seconds]
kiwiroy has joined #crystal-lang
deavmi has quit [Ping timeout: 260 seconds]
deavmi has joined #crystal-lang
ur5us has quit [Ping timeout: 264 seconds]
renich has joined #crystal-lang
ur5us has joined #crystal-lang
renich has quit [Quit: Leaving.]
renich has joined #crystal-lang
Stephie has quit [Ping timeout: 264 seconds]
Vexatos has quit [Ping timeout: 264 seconds]
Stephie has joined #crystal-lang
Vexatos has joined #crystal-lang
HumanG33k has quit [Ping timeout: 264 seconds]
HumanG33k has joined #crystal-lang
<FromGitter> <summer-espresso> @gregoryc it's just because unfortunately the situation of std::regex is rather bad (especially for c++) ⏎ ⏎ 1) https://www.reddit.com/r/cpp/comments/e16s1m/what_is_wrong_with_stdregex/ ⏎ 2) https://stackoverflow.com/questions/52697265/why-is-c-regex-so-slow ⏎ 3) https://dzone.com/articles/introduction-to-regular-expression-with-modern-c ... [https://git
<FromGitter> ... ter.im/crystal-lang/crystal?at=61711af8ee6c260cf72ee08f]
Chillfox has quit [Quit: Leaving]
ur5us has quit [Ping timeout: 264 seconds]
<FromGitter> <alexkutsan> Hello, ⏎ Have probably rather dummy question regarding crystal syntax. ⏎ Is there an ability to pass into the function both variable and some code block? ⏎ ⏎ I would like to write code like this: https://play.crystal-lang.org/#/r/c3ax ... [https://gitter.im/crystal-lang/crystal?at=617121802197144e8479a3c1]
antoszka has quit [Ping timeout: 258 seconds]
mookie has quit [Remote host closed the connection]
mookie has joined #crystal-lang
<FromGitter> <alexkutsan> Answer to my question is there :https://play.crystal-lang.org/#/r/c3cq
sorcus has quit [Quit: WeeChat 3.3]
sorcus has joined #crystal-lang
antoszka has joined #crystal-lang
renich has quit [Quit: Leaving.]
<FromGitter> <beta-ziliani> Sorry to chip in late @Val, but this is a known bug that will be fixed for 1.2.1, coming soon. It's related to class variables with a regex.
<FromGitter> <Blacksmoke16> @alexkutsan any reason to not just use `yield` there?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/c3ep
sagax has joined #crystal-lang
<FromGitter> <jrei:matrix.org> @Blacksmoke16: better: https://play.crystal-lang.org/#/r/c3f6
<FromGitter> <dscottboggs:matrix.org> i did not know about this syntax. useful!
<FromGitter> <Blacksmoke16> well there you go :P
<FromGitter> <Blacksmoke16> :magic:
<FromGitter> <gregoryc> No, but I was using PCRE and C, and Crystal was faster, and I used non-recompiled regexp (without optimizations on), and Crystal was faster. @summer-espresso
<FromGitter> <gregoryc> *with optimizations on
<FromGitter> <gregoryc> with std::regex and boost::regex
<FromGitter> <gregoryc> I don't know why
<FromGitter> <gregoryc> I assume it would have to do with multithreading somehow
<FromGitter> <gregoryc> Crystal is very multithreaded
<FromGitter> <gregoryc> Maybe LLVM is doing optimizations
<FromGitter> <Blacksmoke16> Crystal is not multithreaded by default, so that cant be it
<FromGitter> <gregoryc> I don't know
<FromGitter> <gregoryc> There are fibers
<FromGitter> <Blacksmoke16> can you make a gist of the code?
<FromGitter> <gregoryc> I don't care that much
<FromGitter> <asterite> running a regex will block all fibers, I don't think fibers or multithreading have something to do with this
<yxhuvud> block how?
<FromGitter> <jemc> It's CPU bound rather than IO bound, so it won't yield the CPU to other fibers
<yxhuvud> ah right. I tend to run with the multi threaded flag on so it confused me :D
<FromGitter> <Val> Ok, thank you!
<FromGitter> <99monkey> ```code paste, see link``` ⏎ ⏎ hi all, I'm trying to get typealias outside class User, is it possible? Thanks [https://gitter.im/crystal-lang/crystal?at=61719d97cd4972068b5e484a]
kiiNODA has joined #crystal-lang
<FromGitter> <Blacksmoke16> does that not work?
<kiiNODA> Hi there! I'm loading routes & commands from a YAML file. Afterwards, for any matching route I run what is in commands, using Process.run(). Before running, I do a string substitution in commands with the values that I extract from the route. Do I need to sanitize the values I get for :client and :branch? My Process.run is called with the shell set to false. Any help is much appreciated.
<FromGitter> <oprypin:matrix.org> kiiNODA, show example
<FromGitter> <Blacksmoke16> @99monkey I'd also consider not using named tuples for modeling data, depending on your exact use case, it would probably be better to use a struct
<FromGitter> <99monkey> @Blacksmoke16 i'm playing with ORM way like this ⏎ ⏎ ```Query(User).where({name: "doe"}).order(:age).map(&.age)``` [https://gitter.im/crystal-lang/crystal?at=61719fb77db1e3753e53b2b6]
<kiiNODA> @oprypin - on line 28, should I sanitize what I receive from my route segment? all this gets done with Kemal.
<FromGitter> <99monkey> ```class Query(T) ⏎ .... ⏎ def where(args : T::Params) ⏎ ``` [https://gitter.im/crystal-lang/crystal?at=6171a0199d20982e4fd29066]
<FromGitter> <Blacksmoke16> you know methods has named args. you can do like `.where(name : "doe")`
<FromGitter> <dscottboggs:matrix.org> ``````
<FromGitter> <99monkey> thanks, but its generic, so i wanna get exception trying to send not valid field
<FromGitter> <99monkey> `.where(blablah: "doe") `
<FromGitter> <Blacksmoke16> could ofc be more explicit and setup the method to be like `def where(*, name : String, age : Int32)`, might have to them them nilable tho, or use a few overloads
<FromGitter> <Blacksmoke16> but what you have should work from what i can tell
<FromGitter> <Blacksmoke16> oh, you want to get it off `T`
<FromGitter> <99monkey> thats the deal
<FromGitter> <Blacksmoke16> i dont think you can do that. I remember seeing an issue about this, let me dig it up
<FromGitter> <Blacksmoke16> https://github.com/crystal-lang/crystal/issues/8180 somewhat related
<FromGitter> <99monkey> i tried solve this by ⏎ ⏎ ```class User ⏎ class Params < NamedTuple(name: String) ⏎ end ⏎ end``` ⏎ ⏎ it should work but it's not [https://gitter.im/crystal-lang/crystal?at=6171a1c42197144e847af030]
<FromGitter> <Blacksmoke16> also highly advise not inheriting stdlib types
<FromGitter> <99monkey> got it
<FromGitter> <Blacksmoke16> are you manually defining the `Params` alias?
<FromGitter> <Blacksmoke16> like something the user needs to define to determine what things can be filtered on?
<FromGitter> <Blacksmoke16> you could do like `Query(User, User::Params)` i think
<FromGitter> <claudiug> here, crystal people, any active, maintain and use web framework?
<FromGitter> <claudiug> amber gitter is like a host town :)
<FromGitter> <Blacksmoke16> what are you wanting to make? there are quite a few
<FromGitter> <claudiug> we have an ruby api with react frontend
<FromGitter> <claudiug> so, I would like to build and API
<FromGitter> <claudiug> some cors, pg library, json, router, etc, logging, middleware, etc
<FromGitter> <claudiug> thx u
<FromGitter> <claudiug> will have a look
<FromGitter> <claudiug> amber was an easy bet to show to my colleges as is very similar with rails, as we ae using rails-api
<FromGitter> <Blacksmoke16> spider-gazelle would be closest to rails. but if that's not a requirement Athena and Lucky are a bit more unique but have some pretty cool features
<FromGitter> <claudiug> understood
<FromGitter> <claudiug> usage in general in crystal seems low
<FromGitter> <claudiug> that will a difficult fight to tackle, as most ofthem are inclined to used either go, or python instead of ruby
<FromGitter> <Blacksmoke16> it's a newer lang so yea, not going to have as large of an ecosystem as Ruby
<FromGitter> <Blacksmoke16> but could be worth it because of the perf and ease of development
<FromGitter> <claudiug> but is crystal an ecosystem that grows, or people try, and move on to other things?
<FromGitter> <Blacksmoke16> :shrug: hard to say, few years ago there were really only 3 frameworks, so def seems like things are being created all the time
<FromGitter> <claudiug> but created for them to show, look maan' I can do this, let go back to xxx language :)
<FromGitter> <claudiug> do you know if there is any big companies that are using crystal?
<FromGitter> <dscottboggs:matrix.org> nah I've been seeing George plugging Athena in here every day for like 2 years lol
<FromGitter> <claudiug> I remember, twitter, groupon, etc :)
<FromGitter> <claudiug> and those do create a lot of free marketing for the language it self
<FromGitter> <claudiug> itself*
<FromGitter> <dscottboggs:matrix.org> a few, listed on the site. I know Nicola is a big supporter/user of Crystal, which sucks because their product is fake
<FromGitter> <dscottboggs:matrix.org> but there are several other small-but-stable businesses running it in prod
<FromGitter> <claudiug> nicola?
<FromGitter> <Blacksmoke16> there was another site, but i dont remember where it is
<FromGitter> <claudiug> the `car` manufacturer?
<FromGitter> <claudiug> I tend not to trust that so much, as people as adding companies even if they write 1k loc, then remove it
<FromGitter> <claudiug> :)
<FromGitter> <dscottboggs:matrix.org> ye
<FromGitter> <Blacksmoke16> we use https://github.com/Blacksmoke16/oq in prod :P does that count?
<FromGitter> <claudiug> nice
<FromGitter> <claudiug> it counts
<FromGitter> <claudiug> thx u for the info, i guess, crystal will be maybe next year :P
<FromGitter> <claudiug> developers dont want to try, as it not used and not hype :(
<FromGitter> <Blacksmoke16> i mean its deff used, but not as popular as Python or Ruby etc
<FromGitter> <Blacksmoke16> that's part of your job 😉
<FromGitter> <claudiug> I will do try to build some cli tools, as is faster and nicer than python
<FromGitter> <Blacksmoke16> 👍
<repo> claudiug: you're not associated with meso by chance? :)
<repo> so.. crystal needs "hype"? :)
deavmi_ has joined #crystal-lang
deavmi has quit [Read error: Connection reset by peer]
Munto has quit [Ping timeout: 260 seconds]
<FromGitter> <636f7374> Hello everyone, I have a tricky question, how to cancel IO.copy or IO.read / write in advance (may be earlier than read_timeout, write_timeout), I don't want to close this IO, I just want to cancel this operation, I want to reuse it in the future This IO. (You can use SetReadDeadline to do it in Golang).
<FromGitter> <jrei:matrix.org> Cancel? You can't
<FromGitter> <jrei:matrix.org> Break the big operation to multiple, sequential smaller ones
<FromGitter> <jrei:matrix.org> You meant cancel before executing, or while being performed!
<FromGitter> <dscottboggs:matrix.org> yeah I would look at the source to see how Go implements that. I was under the impression file reading/writing was a kernel operation that you kick off with a syscall and have no further control over
<FromGitter> <636f7374> You meant cancel before executing, or while being performed? (Yes, while being performed).
<FromGitter> <636f7374> Okay, thanks for your help.
<FromGitter> <636f7374> To be exact is `TCPSocket`.
<FromGitter> <jrei:matrix.org> @636f7374: I'm not sure `SetReadDeadline` in Go does what you thing it does
<FromGitter> <jrei:matrix.org> > ReadTimeout covers the time from when the connection is accepted to when the request body is fully read (if you do read the body, otherwise to the end of the headers). It's implemented in net/http by calling SetReadDeadline immediately after Accept.
<FromGitter> <jrei:matrix.org> And in Crystal, there is a `read_timeout` property
<FromGitter> <636f7374> @jrei:matrix.org @dscottboggs:matrix.org Ok thanks for your help. :)
Munto has joined #crystal-lang
<FromGitter> <636f7374> Sorry everyone, interrupted again, I looked it up, In Golang, it seems that `SetReadDeadline` can indeed do it.
<FromGitter> <636f7374> Ian Lance Taylor On Wed, Jun 5, 2019 at 12:10 AM Kurtis Rader <kra...@skepticism.us> wrote: ⏎ ⏎ > > On Tue, Jun 4, 2019 at 11:53 PM Inada Naoki <songof...@gmail.com> wrote: ⏎ >> ⏎ >> conn.SetReadDeadline(time.Now()) ... [https://gitter.im/crystal-lang/crystal?at=6171d1aff2cedf67f99ad174]
<FromGitter> <636f7374> I see `read_timeout=`, `write_timeout=` use `IO::Evented` (`Crystal::EventLoop`, `Crystal::Scheduler`) to achieve this goal (`TimeoutError`), It seems that it can only be applied to future Read calls in Crystal, I'm working on. 🧐
<FromGitter> <jrei:matrix.org> It is about timeouts. I was assuming you'd want to be able to cancel the operation when wanted?
<FromGitter> <jrei:matrix.org> i.e. arbitrarily
<FromGitter> <636f7374> @jrei:matrix.org Sorry, to be exact, I want to interrupt before `read_timeout=`, `write_tiemout=`.
<FromGitter> <jrei:matrix.org> After the timeout is reached you mean? That's how it is supposed to work
<FromGitter> <636f7374> @jrei:matrix.org Interrupt while executing `IO.read` / `IO.write` operation, For example, I set `read_timeout=30_i32.seconds`, but I want to interrupt the operation after 10 seconds or 5 seconds during execution.
<FromGitter> <jrei:matrix.org> Ha yes, not possible
<FromGitter> <jrei:matrix.org> Like in Go too, not possible. This timeout has to be defined before hand.
<FromGitter> <jrei:matrix.org> What's your usecase anyway?
<FromGitter> <dscottboggs:matrix.org> yeah, why not define it ahead of time?
<FromGitter> <636f7374> I am making a proxy server. I establish a long connection with the proxy server. Just like KeepAlive, I cannot predict the progress of the transmission, but I can know that the client or server is disconnected. I don’t want to close the socket, but I want to get rid of IO.read / IO.write in progress, because I will continue to use this Socket in the future.
ur5us has joined #crystal-lang
<FromGitter> <636f7374> Sometimes the client (Source) has been disconnected, the local proxy server needs to notify the remote proxy server, the remote proxy server is reading the destination and sending it to the local proxy server, which takes up the write operation, I cannot notify the local proxy server, and write at the same time Is not safe.
<FromGitter> <jrei:matrix.org> You can make smaller IO operations
<FromGitter> <jrei:matrix.org> And have two connections
<FromGitter> <jrei:matrix.org> Maybe it is better to do this on the client side?
<FromGitter> <636f7374> @jrei:matrix.org Yes, another way is to create a special socket to pass instructions, Thank you for taking the time to answer my question, it is greatly appreciated.
<FromGitter> <jrei:matrix.org> No problem. What kind of app is it?
kiiNODA has quit []
<FromGitter> <636f7374> I rethinked what I can do. 🤔
<yxhuvud> While it isn't possible to cancel an ongoing read syscall, it is possible to ignore or cancel the poll for an fd being readable. I guess that is what go does. Crystal does not support that (yet?)
<FromGitter> <636f7374> When the remote proxy server receives the "terminate connection with the destination" command sent by the local proxy server, in addition to throwing an exception in the Sent fiber (local proxy server to the destination write operation), at the same time set the Atomic (EnumFlag: :Terminate), the next time Receive fiber (destination to local proxy server write operation) detects this Atomic (EnumFlag), an
<FromGitter> ... exception will be thrown,
<FromGitter> <636f7374> At the same time, Atomic (EnumFlag) is added to the operations during reading and writing. Performing these operations will update the Atomic (EnumFlag) value. If data is being read from the destination, but the data is still not written to the local proxy server (idle), You can reply to the local proxy server command, and close the Socket from the remote proxy server to the local proxy server at the same
<FromGitter> ... time, or Mutex will be better.
<yxhuvud> (theoretically, it is sometimes possible to cancel an actual read call if using io_uring, but neither go or crystal is, yet)
<FromGitter> <636f7374> @jrei:matrix.org An application composed of `SOCKS5` and `WebSocket` and custom instructions, Performing this operation will save the cost of handshaking between the local proxy server and the remote proxy server.
<FromGitter> <636f7374> @yxhuvud Sorry 😆, I don't know anything about the underlying operation, thank you for your answer.
<yxhuvud> basically async socket io on linux use something called epoll. It works by telling the system to watch a file descriptor until it is possible to do the wanted action on it without having to wait. Then wehn it comes back an actual blocking read call is emitted but it finishes really fast then
<FromGitter> <636f7374> @yxhuvud Thank you for answering my confusion about the difference between SetReadDeadline and Crystal.
ur5us has quit [Ping timeout: 264 seconds]