<frojnd>
Yesterday I tried played with HTTP::Client to call api but I was unsuccessful. This is curl in bash I'm trying to transfer to crystal: https://termbin.com/33dy any help appreciate
<FromGitter>
<j8r> I'm gonna figure out what's the best for a 2D matrix: `Hash(Tuple(Int32, Int32), V` or `Hash(Int32, Hash(Int32, V))`
oddp has joined #crystal-lang
<jhass>
frojnd: what did you try, how did it fail?
<FromGitter>
<j8r> The first is probably better memory wise, but not sure about the lookup speed. Essentially, if `Tuple#hash` is as efficient as two `Int#hash`
<jhass>
j8r: static and known bounds?
<FromGitter>
<j8r> Static
<jhass>
like you know it's a 64x64 grid and every cell always has an entry
<FromGitter>
<j8r> Yep
<jhass>
Array(Array(Int32))
<FromGitter>
<j8r> Can't be
<jhass>
or even just Array(In32) and some math
<FromGitter>
<j8r> Array won't be good
<jhass>
x + y*x
<jhass>
eh, + y*x%N
<FromGitter>
<j8r> Because I may access to the last element often
<jhass>
then array is very good
<jhass>
especially a flat one
<FromGitter>
<j8r> Or the middle one
<jhass>
yep
<FromGitter>
<j8r> And all may not be loaded
<FromGitter>
<j8r> Array means having a full matrix loaded in memory
<jhass>
no
<jhass>
especially flat array does not
<FromGitter>
<j8r> How?
<jhass>
and even nested is just a pointer load + offset into that pointer
<FromGitter>
<j8r> For example, I need to load in memory (1, 4) and (56, 32) – only
<FromGitter>
<j8r> But other may be loaded after, as needed
<FromGitter>
<j8r> And other not used removed, etc
<jhass>
yeah, that's just computing the pointer offset from the array base pointer and then two loads on those memory locations
<FromGitter>
<j8r> Then I can use a single StaticArray
<FromGitter>
<j8r> Right?
<FromGitter>
<j8r> Hum no actually nvm
<jhass>
you could it's probably just not faster if it's any big
<FromGitter>
<j8r> Could you show me a carc.in of this please :)?
<frojnd>
jhass: like this: https://termbin.com/dmb0 I don't get any response. I get no errors. Just nothing when calling puts
<frojnd>
Oh... not sure how to add --data-raw..
<frojnd>
I just noticed I missed that part entirelly...
<jhass>
frojnd: hehe yeah. You can just do HTTP::Client.post("https://host/path", headers: HTTP::Headers { "Authorization => ... }, body: {devid: ...}.to_json)
<jhass>
that returns your a response on which you can puts response.body
<jhass>
or pp response for more interesting output with status code and what not
<frojnd>
jhass: Thank you. Gonna try that now :)
<jhass>
need to require "json" for to_json to work :)
<FromGitter>
<j8r> Thanks jhass, I will benchmark this
<jhass>
might make it struct instead of class
<FromGitter>
<j8r> Actually i think it will be faster than hash, no need to bench
<FromGitter>
<j8r> `Array#unsafe_fetch` is `@buffer[index]`
<FromGitter>
<j8r> Hum, the array is nevertheless continuous here
<FromGitter>
<j8r> But I may make initial `nil` to have `Array(T?)` as a word-around
<FromGitter>
<j8r> *work-around
<FromGitter>
<j8r> Looks great nevertheless :D
<FromGitter>
<j8r> And `T` is a StaticArray of StaticArray, this is a chunk
zorp_ has quit [Ping timeout: 264 seconds]
<jhass>
there's crazy optimization techniques to stuff like that, like changing the group function such that values you access often together are also close by in memory. Say you'd always iterate this column first, you could swap x and y. Or you always look at pairs of (x, y) and (x + 1, y +1), could make sure they're stored next to each other in the array etc
<FromGitter>
<j8r> Looks interesting :o !
<FromGitter>
<j8r> In my case, I am still figuring out the design. It's already very good now, and even more thanks to you :)
<FromGitter>
<j8r> `T` would be a tile of squares, which would be rendered to a PNG and sent to the client
<FromGitter>
<j8r> `T` is a Chunk, which olds the grid of static arrays, and I plan also an array of entities
<FromGitter>
<j8r> *holds
<FromGitter>
<j8r> That's a way to know neighbouring entities to check collisions against them (of course I have to get those of the chunk near too)
<FromGitter>
<j8r> That's if the entity is in between
sorcus has quit [Quit: WeeChat 2.8]
zorp_ has joined #crystal-lang
zorp_ has quit [Ping timeout: 260 seconds]
sorcus has joined #crystal-lang
<FromGitter>
<manveru> is ther really no way to do a `Dir.chdir`?
<FromGitter>
<manveru> do i have to spawn a new process for that?
<FromGitter>
<roduquen> Hi, I have problem since update 0.35.1, I cant compile, the linking failed ⏎ ```/usr/share/crystal/src/openssl/bio.cr:24: undefined reference to `*HTTP::WebSocket::Protocol::StreamIO#write<Slice(UInt8)>:Int64' ⏎ /usr/bin/ld: /usr/share/crystal/src/openssl/bio.cr:24: undefined reference to `*HTTP::Server::Response#write<Slice(UInt8)>:Int64' ⏎ /usr/bin/ld: /usr/share/crystal/src/openssl/bio.cr:24:
<FromGitter>
... undefined reference to `*HTTP::Server::Response::Output@IO::Buffered#write<Slice(UInt8)>:Int64' ⏎ /usr/bin/ld: /usr/share/crystal/src/openssl/bio.cr:24: undefined reference to `*Compress::Gzip::Writer#write<Slice(UInt8)>:Int64' ... [https://gitter.im/crystal-lang/crystal?at=5ef1f4ff7ba3965373c3e528]
<FromGitter>
<manveru> oh my
<FromGitter>
<manveru> thanks, i totally overlooked Dir.cd :)
<jhass>
roduquen: Try clearing the cache, rm -rf "$(crystal env CRYSTAL_CACHE_DIR)". If that doesn't help, I feel like that's not the full output, make sure to share the full one in a pastebin
<FromGitter>
<roduquen> it works thanks
<yxhuvud>
"Changes the current working directory of the process" Hmm, I wonder if that is fiber-safe.
<jhass>
what's even the definition of fiber-safe for that
<yxhuvud>
I'd say it is for two fibers being able to act independently and not affect each other. It would probably necessitate for the fiber to keep track a reference to current dir.
<jhass>
so you want to check and potentially change the process directory on fiber context switch? Sounds expensive. And impossible in mult-thread mode
<yxhuvud>
well, in practice it would change only when doing io. Potentially by rewriting relative urls into absolute.
<jhass>
I don't think we can potentially capture everything that could potentially be affected by this in kernel property to sanely emulate it
<jhass>
it also sounds like it would need a global lock around calling external libraries
<yxhuvud>
true. Yeah, that doesn't sound fun
<yxhuvud>
(actually it sounds absolutely horrible)
<jhass>
yes :P
repo has quit [Ping timeout: 265 seconds]
<FromGitter>
<j8r> jhass: the grid won't work for infinite maps :/
<jhass>
of course, why do you think I asked the question I initially asked
<FromGitter>
<j8r> Hopefully, I don't plan to have it ;)
<jhass>
it can work for one dimenision unbounded, but the other needs to fixed
<jhass>
or at least upper bounded
<FromGitter>
<j8r> What would you chose for a 3D matrix, infinite?
<jhass>
the question is not how many dimensions but whether their size and number is fixed
<FromGitter>
<j8r> When I was working on the 3D matrix, not fixed
<FromGitter>
<j8r> Infinite in all directions
<FromGitter>
<j8r> So I guess for a 2D infinite map the solution will be the same then
<jhass>
the same as?
<FromGitter>
<j8r> than a 3D map
<jhass>
I guess
<yxhuvud>
big sparse maps tend to do well with a hash based representation. (except possibly if you are implementing linalg libraries. In that case, see whatever sparse matrix implementations exist. There is a couple of different formats in use)
repo has joined #crystal-lang
<frojnd>
jhass: sorry for such long replies :) I tried HTTP::Client.post("https://host/path", headers: HTTP::Headers { "Authorization => ... }, body: {devid: ...}.to_json) but I get: Error: undefined method 'to_json' for NamedTuple(devid: String)
<FromGitter>
<Blacksmoke16> did you `require "json"`?
<frojnd>
I did it like this: body: {devid: "#{device_id}"}.to_json)
<frojnd>
Ofcourse I did not
<FromGitter>
<Blacksmoke16> well there you go :p
<jhass>
"#{whatever}" -> whatever.to_s :)
<frojnd>
Ah ok thank you,..
<frojnd>
Can I somehow write this oneliner into multiple line other than with \ ?
<jhass>
you shouldn't need any \
<FromGitter>
<Blacksmoke16> what, that `HTTP::Client.post`?
<jhass>
just put newlines pretty much wherever you like
<jhass>
except inside string literals :)
deavmi has quit [Ping timeout: 256 seconds]
deavmi has joined #crystal-lang
deavmi has quit [Quit: Eish! Load shedding.]
deavmi has joined #crystal-lang
<FromGitter>
<jwaldrip> Is the core team going to get an apple development kit? Would hate to see mac support go away with the new changes coming from apple.
<FromGitter>
<jwaldrip> Bonus, it would also bring native support for Crystal to the iPhone.
deavmi has quit [Quit: Eish! Load shedding.]
deavmi has joined #crystal-lang
rocx has joined #crystal-lang
deavmi has quit [Client Quit]
<FromGitter>
<watzon> Support for the new Apple silicon would be awesome. I imagine we're going to either have to wait on LLVM or have someone write a crystal assembler though.
deavmi has joined #crystal-lang
deavmi has quit [Quit: Eish! Load shedding.]
deavmi has joined #crystal-lang
<FromGitter>
<asterite> I think none of us is going to get the new arm mac for a while (pretty expensive here, nobody can fly to the us to grab some), so I think we'll support existing macs for a while... I'm not sure about arm though
<FromGitter>
<jwaldrip> $500 mac mini is the transition kit here in the US. What does that go for down in Argentina?
<FromGitter>
<jwaldrip> I'm sure we could start a campaign to get someone on the core team one.
<FromGitter>
<jwaldrip> I myself would be willing to chip in.
<FromGitter>
<jwoertink> ah interesting. Ok, that might work. Thanks!
<FromGitter>
<Blacksmoke16> but seems kinda odd thing to catch, like would that ever make sense?
<FromGitter>
<Blacksmoke16> `attr x : String = raise "oops"` this i mean
<FromGitter>
<jwoertink> Ok, maybe that won't work. If the value is legit like `x : String = "1"` then it fails with `undefined macro method 'StringLiteral#name'`.
<FromGitter>
<jwoertink> In my case, if you do a raise there, it causes some other issues. I was just going to not allow a raised value
<FromGitter>
<jwoertink> but I might have to rethink this
<FromGitter>
<Blacksmoke16> well you can check what is passed
<FromGitter>
<wontruefree> @Blacksmoke16 that is what I am doing but slightly different
<FromGitter>
<Blacksmoke16> i.e. `if type_decl.value.is_a? Call`
<FromGitter>
<wontruefree> I was hoping there was a way to do it without gsub or string maniputaltion
<FromGitter>
<Blacksmoke16> if you could convert a `TypeNode` to a `Path` it gets a bit easier, but idt that exists atm
<FromGitter>
<jwoertink> Ah, ok. If it's a Call and the name is "raise"
<FromGitter>
<Blacksmoke16> yea, possible for someone to define their own `raise` method tho
<FromGitter>
<Blacksmoke16> but meh
deavmi has quit [Quit: Eish! Load shedding.]
deavmi has joined #crystal-lang
<FromGitter>
<wout> Is there a way to know if a given class includes a certain module at compile time?
<FromGitter>
<Blacksmoke16> something like `{{MyModule.includers.includes? MyClass}}`
<FromGitter>
<Blacksmoke16> wait, you want to add something to `String`?
<svipal>
yeah
<FromGitter>
<Blacksmoke16> like what?
<FromGitter>
<Blacksmoke16> can you share some code with what you're actually trying to do?
<svipal>
I mean sure it's not something too complex
<svipal>
It's includes_any? and includes_all? which is are variation of includes? with a string as an input
<svipal>
which areù
<svipal>
I could just define them as some modules functions but figured it would be cleaner as class methods
<FromGitter>
<Blacksmoke16> :thinking: how would they be used?
<svipal>
I'm writing a parser for a custom format. You would use them if you wanted to know if a string included any or all symbols from another string, can cook an example if you want but I don't think it's very relevant
<svipal>
I'm trying to find the name of the module in which the class String is defined, can't find it
<FromGitter>
<Blacksmoke16> its not in a module
<svipal>
ok I cry now
<FromGitter>
<Blacksmoke16> but arent those methods essentially just the same as like `str.includes? "foo"` and `str == "foo"`?
<svipal>
nope they aren't
<svipal>
includes?(search : String) returns true if the string contains the search string
<FromGitter>
<Blacksmoke16> right
<svipal>
includes_any?(characters: String) returns true if the string includes any of the characters. Includes_all returns trues if the string includes all of the character, regardless of the order
<FromGitter>
<Blacksmoke16> gotcha
<svipal>
so, is there any way to add to the String class or am I stuck with making them some module's functions ?
<svipal>
so you have to do that *outside* of a module !
<FromGitter>
<Blacksmoke16> right, because the original class wasn't defined in a module
<svipal>
right, I come from Haskell so it feels super weird for me to do anything outside of modules lol
<svipal>
ok
<svipal>
thanks a lot !
<FromGitter>
<Blacksmoke16> yea if something isnt in a module, its said to be on the top level
<FromGitter>
<Blacksmoke16> which is technically a namespace as well
<svipal>
so there is no way to access the top level classes from within a module ?
<svipal>
you can't do something like class ::String
<FromGitter>
<wyhaines> @Blacksmoke16 Hey, do you know offhand of any sites that are using ANY Crystal webish stuff behind the scenes? Kemal, Lucky, Athena, Amber, whatever? Athena is your baby, right? ⏎ ⏎ I'm using Crystal in a side-project-that-has-mutated-to-a-core-feature-of-a-big-project for my employer, and while it's hella too late to not use Crystal, I'm being asked questions about it's usability for developing things
<FromGitter>
... that we've often done with Rails, and so we want to basically just be able to point to some existing sites somewhere in the world and say that they are using Crystal behind the scenes. Know of anything?
<FromGitter>
<Blacksmoke16> are also some topics on forums about it i think too
<FromGitter>
<Blacksmoke16> mps: I'll have a new version out prob tomorrow
<mps>
ok, thanks
<FromGitter>
<didactic-drunk> @wyhaines There was a page listing places where crystal is used but I don't remember where. It listed businesses from a variety of boring industries (finance, legal, etc).
<FromGitter>
<RespiteSage> Oh, nice. I was thinking that a workaround could be using methods (which would be inlined if used) instead of constants, but it's nice that it works with constants.
<FromGitter>
<Uzay-G> > *<oprypin>* @Uzay-G, yes people shared it several times and no it's not a good article ⏎ ⏎ i agree the benchmark is pretty thin but the discussion on the hn thread is nice
<FromGitter>
<wyhaines> Sort of. It still exists as a nodoc `Process.fork`, but since it is unsafe for threaded programs, it's been removed from the public API.
<FromGitter>
<alexherbo2> what is the equivalent?
<FromGitter>
<Blacksmoke16> is there a reason to use it? `Process.run` spawns a new fiber anyway
<FromGitter>
<Blacksmoke16> not exactly the same thing, but prob more thread safe
<FromGitter>
<alexherbo2> I need to run a block async
<FromGitter>
<alexherbo2> in the block, run a command, and when finished send a message
<FromGitter>
<Blacksmoke16> process.run already does that tho
<FromGitter>
<Blacksmoke16> starts a process in its own fiber and waits for it to complete
<FromGitter>
<alexherbo2> Process.run is async?
<FromGitter>
<Blacksmoke16> kinda, however waiting for it to complete would probably block
<FromGitter>
<Blacksmoke16> not 100% sure on exact, code but something like: ⏎ 1) Have a channel specific for the finished responses ⏎ 2) use `spawn do` versus `fork do` ⏎ 3) Instead of directly calling `send`, send the response to the channel ⏎ 4) then do something like `send channel.receive` [https://gitter.im/crystal-lang/crystal?at=5ef26facbb149531edc84ec9]
<FromGitter>
<Blacksmoke16> id maybe wait for someone more familiar with it to give their thoughts :p
<FromGitter>
<didactic-drunk> IO.pipe
<FromGitter>
<Blacksmoke16> but im also curious of some of the code: