ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Fund Crystal's development: | GH: | Docs: | Gitter:
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? ⏎ ⏎ ```"").include? ""``` ⏎ ⏎ 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:
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>
<FromGitter> <Dan-Do> On link 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)``` []
<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``` []
<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:
<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 ⏎
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:
<frojnd> Sorry wrong link:
<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]