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
ur5us_ has joined #crystal-lang
rymiel has quit [Quit: quit]
rymiel has joined #crystal-lang
ur5us_ has quit [Remote host closed the connection]
ur5us_ has joined #crystal-lang
ur5us_ has quit [Ping timeout: 245 seconds]
<FromGitter> <aaaScript> Would anyone know if there's an example or implementation of the following from Ruby? ⏎ ⏎ ```IPAddr.new("127.0.0.1/8").include? "127.1.10.200"``` ⏎ ⏎ I'm basically trying to see if an IP is within the range of a CIDR. Taking a look at the API it looks like Socket::IPAddress may not support it. Wondering if anyone has worked on anything like this before I tackle a custom solution.
<FromGitter> <aaaScript> Looks like there may be some code here I can use as reference: https://github.com/arcage/crystal-ipaddr
ur5us_ has joined #crystal-lang
taskylizard_ has joined #crystal-lang
ur5us_ has quit [Ping timeout: 256 seconds]
<FromGitter> <paulocoghi> @aaaScript On the library readme there is a reference for `nw.includes?(ipv4)`, which seems to be what you are looking for
<FromGitter> <paulocoghi> @asterite Because of this:
<FromGitter> <paulocoghi> https://i.ibb.co/rwBfhdp/kostya.png
<FromGitter> <Dan-Do> On link https://crystal-lang.org/reference/guides/performance.html it's said that `Use string interpolation instead of concatenation`
<FromGitter> <Dan-Do> concatenation is fastest
notzmv has quit [Ping timeout: 245 seconds]
taskylizard_ has quit [Ping timeout: 250 seconds]
<yxhuvud> @straight-shoota: While ruby doesn't have overloading, it DO have separate unary and binary +.
<yxhuvud> unary is referred to as @+.
<yxhuvud> in method definitions etc.
<yxhuvud> eh, +@.
notzmv has joined #crystal-lang
<FromGitter> <Dan-Do> How to push items to Slice?
<FromGitter> <naqvis> you can’t push, but use index [] operator
<FromGitter> <naqvis> if you need pushing items then Slice doesn’t look like right choice for your use case
<FromGitter> <Dan-Do> How about Pointer?
<FromGitter> <Dan-Do> With Slice, I can use .to_a then push then convert back to Slice. But I don't think it's efficient
<FromGitter> <naqvis> Slice is Pointer in disguise
<FromGitter> <naqvis> what’s your use case?
<FromGitter> <christopherzimmerman> Why not just use an array? If you need to access the pointer you can do that as well, but it gives you all the utility of resizing and appending.
<FromGitter> <Dan-Do> I have a fun in C binding return Pointer(Void). Actually it's an array of UInt64. Now I want to push more items to it
<FromGitter> <Dan-Do> @naqvis I see this `private def compress(src : Slice, dst : Slice)` on your snappy lib.
<FromGitter> <Dan-Do> I don't know what is the type of Slice? Is it Slice(UInt8) or ...?
<FromGitter> <naqvis> i used that as a type annotation, but use-case in that particular shard is `Slice(UInt8)`
<FromGitter> <naqvis> > I have a fun in C binding return Pointer(Void). Actually it's an array of UInt64. Now I want to push more items to it ⏎ ⏎ you can do something like ⏎ ⏎ ```my_c_fun(arr.to_unsafe)``` [https://gitter.im/crystal-lang/crystal?at=619f8a56197fa95a1c8e202a]
<FromGitter> <Dan-Do> Is it fast? because it's told that `Use structs when possible`
<FromGitter> <Dan-Do> Array is Class
<FromGitter> <Dan-Do> I did like this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=619f9080cd3f06175dd5178c]
<FromGitter> <Dan-Do> BTW, do you have any experience in C++ binding? I want to make binding for simdjson
<FromGitter> <Dan-Do> Is it the same as C binding?
taskylizard__ has joined #crystal-lang
<straight-shoota> Dan-Do does that code even work? At one point you treat `s_from_c` as a struct with a `size` field, and then it's a pointer to a UInt64 array
<straight-shoota> I can't see how that would be valid
<FromGitter> <Dan-Do> Oops, just a pseudo code, the `size` is gotten from C lib as `out`
<straight-shoota> ah, okay
<straight-shoota> Still, that's most likely unsafe. I assume the pointer comes from the lib, so the memory is allocated there as well.
<FromGitter> <Dan-Do> Yeap, it's a struct with data and size :)
<straight-shoota> You can't just add more data to that, unless you're sure there is enough capacity for that
<FromGitter> <Dan-Do> Does Crystal assure that when running this code `Slice(UInt64).new`?
<straight-shoota> Like if the array is allocated for 10 elements, but only 4 are populated. The size is 4 and you can still add 6 more items.
<straight-shoota> No. In that constructor you tell slice that you have a pointer that points to size + 1 elements. It's your responsibility to make sure there is actually capacity for size + 1
<FromGitter> <Dan-Do> Let me check the crystal's Slice code :)
<FromGitter> <Dan-Do> You're correct, that code doesn't allocate memory, just wrap the Pointer
<straight-shoota> Yes, that's what the documentation says:
<straight-shoota> https://crystal-lang.org/api/1.2.2/Slice.html#new%28pointer%3APointer%28T%29%2Csize%3AInt%2C%2A%2Cread_only%3Dfalse%29-class-method
<FromGitter> <Dan-Do> It's strange that I run that code for 20 minutes and it keeps running, without any seg fault or memory dump
<straight-shoota> Sure, it can work fine. But it's unreliable. You can't know what it *actually* does
ua_ has quit [Ping timeout: 250 seconds]
<FromGitter> <Dan-Do> Yeah, got it
ua_ has joined #crystal-lang
<FromGitter> <Dan-Do> Wow, I see Pointer::Appender ⏎ https://crystal-lang.org/api/master/Pointer/Appender.html
hightower2 has quit [Ping timeout: 250 seconds]
taskylizard has joined #crystal-lang
taskylizard__ has quit [Ping timeout: 260 seconds]
taskylizard has quit [Ping timeout: 260 seconds]
hightower2 has joined #crystal-lang
<hightower2> Ah remind me please, what's the best way to check if x == y is actually the same object/instance (and not just being equal according to `==`)
<FromGitter> <Blacksmoke16> `x.same? y`
<FromGitter> <Blacksmoke16> only works for reference types ofc tho
<hightower2> mm, nice, thanks
<frojnd> Hi there. I would like to match only part that is before `-` together with `-` so the only not matched part of a string would be: `string I would like not to match` But I don't know how to do it. I'm missing part how to also select `-` together with a following space: https://regex101.com/r/bJ1mU0/1
<frojnd> Sorry wrong link: https://regex101.com/r/RQ7eaS/1
<frojnd> ^ correct one
<hightower2> yeah look-ahead/look-behind don't become part of match. Maybe you need: ^.+?-\s*
<frojnd> Much better! Thank you
hightower2 has quit [Ping timeout: 268 seconds]
ur5us_ has joined #crystal-lang
hightower2 has joined #crystal-lang
hightower2 has quit [Ping timeout: 256 seconds]
fifr has quit [Ping timeout: 265 seconds]
fifr has joined #crystal-lang
ur5us_ has quit [Ping timeout: 245 seconds]