Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
<FromGitter>
<j8r> you can replace the `k` by `_` in the `min_by` line (avoid allocation)
<FromGitter>
<j8r> For other questions, hasn't followed
<FromGitter>
<j8r> That's sure you'll have a ton of issues, but i think having a bare minimum working app with lots of bugs and then worrying about edge cases is better
<FromGitter>
<girng> @j8r yeah, i will work on optimization l8er. im just worried about round trip time when notifying the user. i need `client.send` to be sent, ONLY if `find_first[1].send` was successfully (and acknowledged that they received it).
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
<FromGitter>
<j8r> Hum I guess to receive a message thus, and check the infos inside
<FromGitter>
<j8r> ... will be needed
<FromGitter>
<j8r> A connection isn't a transfere, there are bi directional transfer of infos
<FromGitter>
<j8r> Maybe the client can send "Hey, I've this version of the client, I'm in Asia and my account id is a1b2d3"
<FromGitter>
<girng> @j8r Here, I made a diagram (https://i.imgur.com/Q6XA1G0.jpg). The border thickness of the lines represent the order, SMALLEST happens first
<FromGitter>
<girng> Is there a way to make sure a `.send` method was acknowledged/received/written, before continuing the execution
rohitpaulk has joined #crystal-lang
sz0 has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 248 seconds]
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
<FromGitter>
<Blacksmoke16> what class does `0...10` belong to?
<FromGitter>
<Blacksmoke16> nvm its a Range
<FromGitter>
<bew> @girng If you use the methods offered by Crystal, it'll block the current fiber until that data will be sent. If you absolutely need to be sure that data has been received and saved you can always require the other end of the connection to send you an acknowledgement
<oprypin>
faustinoaq, if you disregard the fact that you're dealing with a file (really just dealing with a line/string), it's quite doable. So start at the index and make a loop scanning leftwards for a boundary, then a loop scanning rightwards
<z64>
does anyone happen to have experience with Zlib/Flate, specifically with debugging infinite blocking behavior? tried searching for issues similar to the one i'm having, but not sure if issues i found are the same issue i'm seeing
<z64>
*when using Reader
<z64>
if someone could take a look, i have a repo here with a sample blob of data that reproduces the issue https://github.com/z64/zlib-freeze ; i've tried quite a few things but i'm totally stuck at this point
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 265 seconds]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
<FromGitter>
<Qwerp-Derp> How can I get the type of a function's arguments?
snsei has quit [Ping timeout: 255 seconds]
<FromGitter>
<S-YOU> typeof(arg)?
<FromGitter>
<Qwerp-Derp> Damn, I explained this badly
<FromGitter>
<S-YOU> in macro?
<FromGitter>
<Qwerp-Derp> OK so I have a function `foo`, and I want to fetch the argument's type, but I don't know what the argument is called, I just know there's one argument
<FromGitter>
<Qwerp-Derp> yeah, in macro
<FromGitter>
<S-YOU> still possible with typeof({{arg}}) imo
<FromGitter>
<S-YOU> or arg.is_a?(SomeType) ?
<FromGitter>
<Qwerp-Derp> But the thing is I don't know what the arg is called
<FromGitter>
<Qwerp-Derp> Like I have a macro `get_type(foo)`, which fetches the argument type of a function `foo`. The thing is, how do I implement `get_type`?
<FromGitter>
<Qwerp-Derp> That's the question I'm trying to ask
<FromGitter>
<S-YOU> ah, I am not sure you can define your own function for macro as far as I know. but most of the time, there is built-in.
<FromGitter>
<Qwerp-Derp> The reason why I'm asking this question is because I have to parse a language, which has dynamic types
<FromGitter>
<Qwerp-Derp> Once the type is parsed into Crystal it'll be something like a `JSON::Any`, in that it's an overarching type that has all other types within it
<FromGitter>
<Qwerp-Derp> But then I'm interacting with functions which have specific types as arguments, e.g. `String`
<FromGitter>
<Qwerp-Derp> I need to figure out what argument the function has so I can downcast the type properly
<FromGitter>
<Qwerp-Derp> Is this even possible in Crystal?
<FromGitter>
<S-YOU> In my understanding, it has to be done at compilation phase, not runtime I guess, unless you can have extra field with that information in your data structure. ⏎ But I don't know. There may be brilliant ideas out there.
<FromGitter>
<Qwerp-Derp> Alright, can I pass a function as an argument then?
<FromGitter>
<Qwerp-Derp> Or is that impossible in Crystal
<FromGitter>
<bararchy> Does Crystal have support for JSONC ?
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 276 seconds]
<FromGitter>
<S-YOU> You can wrap function inside a proc like -> { yourfunction }, and pass to function. If yourfunction is a C function, ->yourfunction just work with current version of crystal.
Raimondi has joined #crystal-lang
<FromGitter>
<DRVTiny> Hello4all! ⏎ I've write simple code to run Kemal in multi-processes mode: https://pastebin.com/chA2KqbR ⏎ All works well, but when i sending HUP signal to the master process and than master process trying to send TERM to first child, i've got logged this (see last 4 lines): ⏎ ⏎ ```code paste, see link``` ... [https://gitter.im/crystal-lang/crystal?at=5af03d2d03cafa797b31f311]
shalmezad has joined #crystal-lang
kosmonaut has quit [Remote host closed the connection]
<FromGitter>
<codenoid> hi, how to convert YAML::Any to Hash
<FromGitter>
<codenoid> as_h
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 255 seconds]
<FromGitter>
<bararchy> `.to_h`
<FromGitter>
<bararchy> @oprypin oprypin how do I draw the global_boundries of a sprite ?
<FromGitter>
<bararchy> `global_bounds`
duane has joined #crystal-lang
DTZUZO has quit [Read error: Connection reset by peer]
<FromGitter>
<faustinoaq> @gdotdesign I guess you can use `gdb` for that 😅
<FromGitter>
<faustinoaq> @oprypin Ok, I'm trying that using `StringScanner` 👍
Raimondi has quit [*.net *.split]
Guest21720 has quit [*.net *.split]
oprypin has quit [*.net *.split]
pabs has quit [*.net *.split]
thews has quit [*.net *.split]
Liothen has quit [*.net *.split]
shelvacu has quit [*.net *.split]
Raimondii is now known as Raimondi
BlaXpirit is now known as oprypin
thews has joined #crystal-lang
thews has joined #crystal-lang
thews has quit [Changing host]
<FromGitter>
<DRVTiny> How to terminate/wait forked processes correctly to avoid zombies?
DTZUZO has joined #crystal-lang
snsei has joined #crystal-lang
jeromegn has joined #crystal-lang
<jeromegn>
oh hey there, long time no see :)
<jeromegn>
I was wondering if Crystal's C bindings were a "zero cost" abstraction. Is it doing FFI?
<jeromegn>
I'm building V8 bindings (it's a C++ lib, but I've made a C bridge) and it's working nicely. Trying to make sure I'm not losing perf by crossing the Crystal <-> C boundary.
snsei has quit [Ping timeout: 265 seconds]
<FromGitter>
<asterite> it's zero cost. When you call a C function, the generated call is exactly that C call
<FromGitter>
<asterite> (which might be good or bad, depending on how you see it)
<jeromegn>
Nice, that's what I thought I read, but wanted to make sure.
<jeromegn>
V8 will assign an isolate (the JS VM) to the current thread when creating one. If I want to distribute across threads in my Crystal app, I'd have to either add that logic within C or fork my Crystal process, right?
Raimondi has quit [Read error: Connection reset by peer]
Raimondi has joined #crystal-lang
<FromGitter>
<asterite> not sure
<jeromegn>
does forking create a new thread?
<FromGitter>
<hmans> It should, since it creates a whole new process (right?)
<z64>
jeromegn: v8 bindings sound awesome - is this available to follow on github, etc somewhere yet?:)
<jeromegn>
not yet!
<jeromegn>
if I ever get somewhere useful though, it sure will
<jeromegn>
our company is big on open source, our main product is mostly open sourced (https://fly.io)
<z64>
sure thing. i've been mucking with duktape but haven't been all too thrilled with it
<jeromegn>
first it was all node.js, because it already has v8 built-in. but we don't like it that much. now I'm playing with go and Crystal (also dabbled with Rust's v8 bindings.) go's are pretty far along, but each call to C has a cost, so I need to write big C functions to handle most of the work so I don't cross the boundary too often
<jeromegn>
I don't have to worry about that with Crystal
kurko_ has joined #crystal-lang
hightower2 has joined #crystal-lang
snsei has joined #crystal-lang
<crystal-gh>
[crystal] straight-shoota opened pull request #6071: Use qualified type Crystal::Path in compiler specs (master...jm/feature/qualified-crystal-path) https://git.io/vpoiy
<FromGitter>
<wrq> does Crystal have Some, None? How do I check for a value that may not exist?
<FromGitter>
<wrq> sorry if this is a dumb question
<FromGitter>
<wrq> /msg
<Guest28139>
@wrq you use nil
Guest28139 is now known as RX14
<RX14>
@wrq we don't need Some/None because you can just union the type with nil and it's the same effect
<FromGitter>
<wrq> OH, so nil is not like ruby nil then? That's an ingenious choice
<RX14>
it's not like java/ruby in that you can assign nil to anything
<RX14>
that wouldn't be type safe
<RX14>
you can use if var (flow typing) to deal with nil
<RX14>
you can use methods on nil like .try
<RX14>
it's the best bits of opetionals and flow typing
<FromGitter>
<oprypin> it really is kinda like ruby nil but with compile time safety
<FromGitter>
<wrq> I see, that's what I was thinking you meant. Thanks! I really like that
rohitpaulk has quit [Ping timeout: 256 seconds]
kurko_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
rohitpaulk has joined #crystal-lang
kurko_ has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 265 seconds]
rohitpaulk has joined #crystal-lang
<jeromegn>
is storing C callbacks in a class variable the only way to prevent GC? wouldn't it also be ok if it was stored as an instance variable, it would live as long as the instance?
<FromGitter>
<bew> Yeah it's ok, the main thing is that you need to store it somehow in Crystal land before sending it to C
<FromGitter>
<oprypin> jeromegn, don't you think storing and deleting N callbacks is worse than storing 1, even if the N can sometimes be 0 ?
<FromGitter>
<oprypin> can be ||= as well if you're concerned
<jeromegn>
@oprypin: you mean storing 1 callback that "dispatches" to various other callbacks?
<FromGitter>
<oprypin> wasn't that what you meant by "class variable"?
<jeromegn>
well I was referring to the crystal book, the part about C callbacks, it says you should store it in a class variable :)
<FromGitter>
<oprypin> i have 1 global callback in crsfml but that's because it's very special, it probably is not applicable everywhere
<FromGitter>
<oprypin> instance var works more generally
<jeromegn>
@bew: so if I sent a Proc directly to C and it worked multiple times, that's just luck (and my program being short lived, so never GCed)
<jeromegn>
yea I'll do instance vars then, sounds good
<FromGitter>
<oprypin> probably
<jeromegn>
pretty sure a dispatcher would work fine too! I'll try a few things.
<FromGitter>
<oprypin> jeromegn, sometimes c libraries allow you to store additional data to pass to the callback
<jeromegn>
yea
<FromGitter>
<oprypin> then you can use 1 callback which uses that data per object
<FromGitter>
<oprypin> that's actually very widespread, now that i think about it. so someone who wrote the docs just said class variable as a matter of fact
<jeromegn>
V8 (the one I'm working with) does. it's a bit odd though. when I get that data (the void pointer) in C, it won't let me call it from C. I either get "expression preceding parentheses of apparent call must have (pointer-to-) function type" or "expression must be a pointer to a complete object type"
<jeromegn>
oh, I guess I don't have to call it from C
<jeromegn>
I can unbox from crystal
<FromGitter>
<oprypin> ofc you can't just use it like `void* a; a()`
<FromGitter>
<oprypin> but i don't think you're supposed to pass a function there but rather the actual object
<FromGitter>
<j8r> Yes
kurko_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
snsei has quit [Remote host closed the connection]
<FromGitter>
<DRVTiny> Nobody can tell me that i can't do process handling from the signal handler :(
<FromGitter>
<bew> What?
<FromGitter>
<bew> @DRVTiny is there a implicit question in your statement?
rohitpaulk has quit [Ping timeout: 268 seconds]
<oprypin>
DRVTiny, signal handlers must be instantaneous. could spawn a fiber from it tho
<FromGitter>
<DRVTiny> Main difference: child_p.kill && child_p.wait - from the main fiber (1) and from the signal handler (2)
<FromGitter>
<j8r> You are doing multi-thread?
<FromGitter>
<j8r> I see `Process.fork`
<FromGitter>
<DRVTiny> forks. Mulitasking, not mulithreading
<FromGitter>
<j8r> 👍
<FromGitter>
<DRVTiny> I'm not sure, but it seems that multithreading is very difficult to implement in LLVM-based languages: in Rust this leads to painful threading model, in Julia - threads N.I.Y (only experimental support), in Crystal - the same situation.
hightower2 has quit [Ping timeout: 268 seconds]
<FromGitter>
<j8r> Yes better to have simply N instances like in Node.js (and even some Go apps)
<FromGitter>
<DRVTiny> Many LLVM-based languages uses GC, Rust is an rare exclusion from that rule. Maybe, stable and not "performance-killing" implementation of thread-safe GC is a main problem of LLVM-based languages?
<FromGitter>
<j8r> How swift handle this?
<FromGitter>
<DRVTiny> @j8r It is so in my favorite web framework, Mojolicious, too :)
<Yxhuvud>
by not having a GC. (dunno how their reference counting works wrt threads though
kurko_ has joined #crystal-lang
<FromGitter>
<DRVTiny> @j8r Don't know, but i believe that Apple can pay enough time/money to develop multithreaded language based on LLVM compiler
<FromGitter>
<DRVTiny> Am i right that Asterite is no longer involved in Crystal language development?
Liothen- has quit [Quit: The Dogmatic Law of Shadowsong]
Liothen has joined #crystal-lang
Liothen has joined #crystal-lang
<z64>
@DRVTiny: asterite still contributes to the project where he likes to & when he has time to dofg
<z64>
*to do so
<FromGitter>
<DRVTiny> @z64 Can users of Crystal pay to asterite so that he could spend more time developing the Crystal language?
kosmonaut has quit [Remote host closed the connection]
kosmonaut has joined #crystal-lang
<FromGitter>
<S-YOU> In my opinion, multiple threading is difficult because core already using extensively though. ⏎ I don't use GC and Fiber. It works great with multi-threading with pthreads and excellent performance with Intel NUMA cpus.
<FromGitter>
<DRVTiny> Hint: Redis library by stefanwille in my application (many big mgets) shows better performance when using fibers than when using pipelining mode.
<FromGitter>
<S-YOU> libevent is very fast, so it is possible like 100k ~ 200k requests / seconds with built-in fiber in single core, I believe.
<FromGitter>
<girng> good morning
<FromGitter>
<S-YOU> good morning. (going to bed now...)
<FromGitter>
<girng> haha gn
<FromGitter>
<girng> @z64 shoul update that page, 10k+ stars now
<FromGitter>
<girng> and 3000 projects, not 1500
<FromGitter>
<j8r> lots of infos are out of date when we look closely
<FromGitter>
<girng> k, im on wrong
gizmore has joined #crystal-lang
<gizmore>
class gizmore < User; def noob; !!Math.floor(Math.rand); end; end;
<z64>
gizmore: no; if you want scriptable runtime behavior, you would have to write some custom on top of crystal, or use some embedded language like lua/js
<gizmore>
i am thinking of ruby or typescript
<FromGitter>
<r00ster91> i would take ruby then
<FromGitter>
<r00ster91> ruby will also get an official inbuilt jit compiler soon
<gizmore>
also gem stuff is not that bad
<FromGitter>
<r00ster91> yea there are a lot of games
<FromGitter>
<r00ster91> gems*
rohitpaulk has joined #crystal-lang
<FromGitter>
<j8r> @r00ster91 you can't include methods defs inside methods defs
<FromGitter>
<r00ster91> i know but i thought theres maybe some other way to do something similar
<FromGitter>
<r00ster91> im doing that so i dont need to write self. before every method name
justinmcp_ has joined #crystal-lang
<FromGitter>
<bew> Oh no sorry didn't read
faustinoaq has quit [Remote host closed the connection]
faustinoaq has joined #crystal-lang
Liothen has quit [*.net *.split]
DTZUZO has quit [*.net *.split]
jeromegn has quit [*.net *.split]
Yxhuvud has quit [*.net *.split]
tilpner has quit [*.net *.split]
pfl[m] has quit [*.net *.split]
fifr[m] has quit [*.net *.split]
mroth has quit [*.net *.split]
justinmcp has quit [*.net *.split]
tilpner_ is now known as tilpner
jeromegn_ is now known as jeromegn
mroth_ is now known as mroth
Liothen has joined #crystal-lang
Liothen has joined #crystal-lang
<FromGitter>
<j8r> does the block needs to change or not?
<FromGitter>
<j8r> All can be done at compile time?
<FromGitter>
<r00ster91> no i dont think it needs to change
pfl[m] has joined #crystal-lang
fifr[m] has joined #crystal-lang
<FromGitter>
<r00ster91> the problem is my library name is probably a bit too long. So it will be a bit annoying to write the whole time the LibraryName. before the method again at every line
<FromGitter>
<r00ster91> So I thought about something like this but it seems to be a bit complicated :/
<FromGitter>
<bew> @r00ster91 checkout `with ... yield` in the language docs
kurko_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
nominalbear has quit [Quit: ""]
andrewzah has joined #crystal-lang
crystal-lang783 has joined #crystal-lang
crystal-lang783 has quit [Client Quit]
<FromGitter>
<jwoertink> I want to gsub a string with a "\d", but doing "\d" make only the `d` show up, and doing "\\d" makes `\\d` show up. Is there a way to get just 1 backslash?
<FromGitter>
<jwoertink> nevermind. Doing it a different way
<FromGitter>
<oprypin> @jwoertink, `\\d` is correct, you're looking at an escaped string representation
<FromGitter>
<oprypin> it says you'd need to write `\\d` in source code to get the string. it does not say what the string actually is
<FromGitter>
<girng> hi oprypin
<FromGitter>
<oprypin> hi @girng , you wanna explain how `p` works? xD
<FromGitter>
<girng> rofl
<FromGitter>
<asterite> Op
<FromGitter>
<girng> @oprypin i'll take a whack at it off the top of my head.
<FromGitter>
<oprypin> well don't put too much effort into it in case nobody's listening anymore
<FromGitter>
<girng> damn
<FromGitter>
<girng> yeah nvm
<FromGitter>
<j8r> when will Crystal 0.25.0 released?
<FromGitter>
<j8r> Can't wiat 😃
<FromGitter>
<bew> After 1.0 :D
<jeromegn>
ok, C is telling me something has a sizeof 24 bytes, so I padded a struct in Crystal with LibC::Char[24], but I get segfaults. Apparently anything <= 16 will work there. Seems odd to me.
rohitpaulk has quit [Ping timeout: 260 seconds]
<jeromegn>
all those bytes are from protected attributes, which I don't want to touch.