<FromGitter>
<fastcona> Who knows there are request errors across Crystal web frameworks? It look quite bad and need fixing especially spider-gazelle too ⏎ https://www.techempower.com/benchmarks/#section=test&runid=5191fd86-6a2a-405b-b326-f160fc6781b7&hw=ph&test=fortune
<FromGitter>
<fastcona> Probably fixing those errors is utmost priorities right now.
<FromGitter>
<sam0x17> @straight-shoota thanks for the info about the alpine package -- any idea when 0.27.1 will happen?
<FromGitter>
<Blacksmoke16> is there a way to exclude specific ivars from being displayed when doing `pp`?
<FromGitter>
<kingsleyh> ah great - works thanks :)
<FromGitter>
<bajro17> Can someone help me with granite migrations I cant find is there way to declare unique field?
<FromGitter>
<fridgerator> @bajro17 Did you try the amber channel?
<FromGitter>
<schoening> Trying to debug my kemal server here. Just a simple CRUD app. But it does not get any parameters on my json object :/ ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Is there a kemal specific chat? ... [https://gitter.im/crystal-lang/crystal?at=5be83617e0fd6b4360d82b56]
<FromGitter>
<fridgerator> When you use postman, you see the json params?
<FromGitter>
<schoening> No, sorry, bad explaination. ⏎ I use postman for testing. No params. But when I send the same request to postman-echo.com/post it returns with params just fine
<FromGitter>
<fridgerator> do you get anything in `env.params.body` ?
<FromGitter>
<bajro17> @fridgerator I write but there is little slow to get answer then I want see if someone here use it :)
<FromGitter>
<schoening> @fridgerator :o I do! ⏎ *name=test&email=test%40test.com&cellphone=12345678* which are my parameters.. but I did not create a GET request..
<FromGitter>
<fridgerator> in postman, are you setting the content type?
<FromGitter>
<schoening> Was about to say: adding *Content-Type application/json* in postman sorta breaks it for both the postman-echo.com/post and kemal. Which I find confusing..
<FromGitter>
<fridgerator> so thats form-data, not json
rohitpaulk has joined #crystal-lang
<FromGitter>
<schoening> omg
<FromGitter>
<schoening> Well, thx man. I only just downloaded postman. Now it works.. Derp
<FromGitter>
<fridgerator> 👍
rohitpaulk has quit [Ping timeout: 245 seconds]
<oprypin>
Yxhuvud, omg don't recommend those horrible hacks as if they're the best solution (this is regarding `unpack` vs slice)
<oprypin>
kingsleyh, please don't use the previously recommended `to_slice` and `String.new` solutions. this is an imlpementation-specific hack. the proper solution is here: https://crystal-lang.org/api/IO/ByteFormat.html
<oprypin>
as you're looking specifically for LittleEndian, and not just "whatever the current CPU decides to do"
<FromGitter>
<Blacksmoke16> wait so it literally has to be `T`
* Jenz
:O
<FromGitter>
<Blacksmoke16> right, so it matches with the parent generic
<FromGitter>
<Blacksmoke16> that makes sense
<Jenz>
(Not to me)
<Jenz>
(the 5hpj one)
<Jenz>
Thanks oprypin, @Blacksmoke16
rohitpaulk has quit [Ping timeout: 246 seconds]
<FromGitter>
<Blacksmoke16> i think its because the abstract def says it should be of type `T`, i.e. whatever generic you pass the parent class
<FromGitter>
<Blacksmoke16> and since you had it typed as `String` that wouldnt match up with if you did `Around(Bool)` for example, so by setting it to T it knows to use whatever generic the parent class is passed
<FromGitter>
<Blacksmoke16> also anyone else notice their `toplevel.html` isnt being created
<FromGitter>
<Blacksmoke16> i can search for the method name and it shows up in list but 404s when clicking on it, ill file an issue
<FromGitter>
<Blacksmoke16> only happens when macro is only thing on toplevel
_whitelogger has joined #crystal-lang
Jenz has quit [Ping timeout: 268 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 264 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 252 seconds]
<oprypin>
makes sense that there would be bug in such an area :)
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 245 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter>
<dscottboggs_gitlab> @oprypin thanks for letting me know about `String.new` and `to_slice` being a hack, but I don't see what you mean about using IO::ByteFormat on Strings?
<oprypin>
who said about strings
<Yxhuvud>
oprypin: the whole thing as about going to and from string representation.
<oprypin>
well you can encode to bytes and decode
<FromGitter>
<dscottboggs_gitlab> yes the question is how
<oprypin>
well, `String.new` seems to be the right way to convert from bytes to text
<oprypin>
but the context was about 32-bit integers, not bytes
<FromGitter>
<dscottboggs_gitlab> oh so you're saying to convert from `"string".to_slice` to an array of integers rather than from string to bytes in general.
<Yxhuvud>
oprypin: well, ruby don't have proper bytes, so there you have to go to and from integer arrays instead.
* FromGitter
* dscottboggs_gitlab cringes
<FromGitter>
<vladfaust> I'm not awaiting for a much help, but maybe you could paw me the way. I have this example: https://carc.in/#/r/5hpr. What I want is get a valid JSON without double brackets and to make it as performant as possible (i.e. avoid reading from IO to string). One way is to modify `.to_json` (actually, I'm allowed to use any other method, e.g. `.to_bracketless_json`), but maybe there is a more obvious way?
<FromGitter>
<vladfaust> 1) My use-case is lots of Foo's, which are Action objects in a web application
<oprypin>
.to_json(response) ??
<FromGitter>
<vladfaust> No, that's not what I want. I actually want `@payload` to be a variable containing a value for further processing. I cannot use `NamedTuple` for this, therefore I consider `IO` being the best alternative
<FromGitter>
<vladfaust> The thing is that I want this `@payload` to be decorated in the future, e.g. wrap in another JSON
<FromGitter>
<vladfaust> Yeah, can I somehow remove those brackets from the `@payload` without reading from it? :D
<FromGitter>
<vladfaust> 1) `{foo: 42}.to_json(@payload)` without brackets ⏎ 2) Remove brackets from the end and the beginning of `@payload`
<FromGitter>
<vladfaust> Sorry if being to noisy
<FromGitter>
<vladfaust> Okay, nevermind, it's too deep, sorry for disturbing!
<FromGitter>
<dscottboggs_gitlab> no disturbance, sorry we couldn't help
hightower4 has joined #crystal-lang
<hightower4>
Hey @Papierkorb, I just realized your 'cannon' repo is not listed in either crystalshards.org or .xyz
<FromGitter>
<kingsleyh> ah great that's what I was missing
<FromGitter>
<kingsleyh> hmm not quite working as expected
<FromGitter>
<kingsleyh> In Ruby this gives me an Array of Fixnum from Bytes : `b = bytes.unpack("V*")`
<FromGitter>
<kingsleyh> the size of the Array is 4096
<FromGitter>
<kingsleyh> the Bytes size is 16384
<FromGitter>
<kingsleyh> in Crystal - the Bytes size is 16384 - the same
<FromGitter>
<kingsleyh> but `bytes.map(&.to_u32).size` gives me 16384 as it's mapping - so not what I want
<FromGitter>
<kingsleyh> I want 4096
<FromGitter>
<vladfaust> That's because you need to `bytes.to_a.map(&.to_u32).size`
<FromGitter>
<vladfaust> `.map` returns Slice, whilst `.to_a` converts it to an Array
<FromGitter>
<kingsleyh> don't see how that could make any difference
<FromGitter>
<vladfaust> Me too
<FromGitter>
<Blacksmoke16> can you use enums in macros?
<FromGitter>
<vladfaust> The truth is that I'm a web guy, I'm afraid of Bytes 😅
<FromGitter>
<kingsleyh> It could be that for Crystal I can't follow the same path as the Ruby lib I'm porting
<FromGitter>
<vladfaust> @Blacksmoke16 if they're defined in the outer scope - yes?
<FromGitter>
<vladfaust> Enums are types
<FromGitter>
<kingsleyh> I was told that Crystal doesn't need pack/unpack - but I don't really understand why
<FromGitter>
<Blacksmoke16> well more specifically, compare the value off an annotation to an enum
<FromGitter>
<vladfaust> @Blacksmoke16 sorry, had no experience, but I can assume that thus there is no Enum AST node, you cannot do that Enum-specific stuff
<FromGitter>
<Blacksmoke16> `cann[:exclusion_policy].resolve == CrSerializer::ExclusionPolicy::ExcludeAll` works for me
<FromGitter>
<Blacksmoke16> specs pass, ill take it 👌
<FromGitter>
<vladfaust> Marvelous
<FromGitter>
<vladfaust> Turns out a enum value is a Type itself
<FromGitter>
<kingsleyh> 1 int = 4 bytes = so I guess if I have a byte array that is 16384 - I need to chunk it into 4's and do to_u32 on the chunk
<FromGitter>
<kingsleyh> I think
<FromGitter>
<vladfaust> Makes sense! But how to convert four UInt8 to a single UInt32? :thinking:
<FromGitter>
<vladfaust> Just `.to_u32` on an array?
<FromGitter>
<kingsleyh> maybe flat_map could work
<FromGitter>
<kingsleyh> hmm actually no - that would flatten away the 4
<FromGitter>
<kingsleyh> anyway it seems to work
<FromGitter>
<kingsleyh> hmm no it doesn't work :/
<oprypin>
kingsleyh, so i guess you skipped my message
devil_tux has joined #crystal-lang
<FromGitter>
<kingsleyh> oh I didn't see it
<devil_tux>
how to hide logger output if creating dinamically?
<devil_tux>
Log = ::Logger.new(STDOUT)
<FromGitter>
<kingsleyh> oprypin - sorry I don't understand your comments
<FromGitter>
<kingsleyh> I think you are saying in Crystal - we should not convert between Byte array and UInt32 Array?
<FromGitter>
<kingsleyh> I should convert it to a string? and then to UInt32 Array?
<oprypin>
that's fine, just see the documentation I linked
<oprypin>
I'm saying the opposite
<FromGitter>
<kingsleyh> oh I see - you are recommending encode/decode instead
<FromGitter>
<kingsleyh> how do you deal with the Nil cases? ` bytes.in_groups_of(4).map{|chunk| IO::ByteFormat::LittleEndian.decode(UInt32, chunk) }`
<FromGitter>
<kingsleyh> the chunk returns Array(UInt8 | Nil)
<oprypin>
i think you could skip the manual chunk splitting
<FromGitter>
<kingsleyh> I don't think so - as the decoder only gives back a single UInt32
<oprypin>
use IO#read_bytes
<oprypin>
but you'll probably still run into trouble with the right boundary
<oprypin>
what is it supposed to do when there are less than 4 bytes remaining?
<FromGitter>
<kingsleyh> throw an exception
<oprypin>
well perfect then
<FromGitter>
<kingsleyh> the size has to be exactly 4096 as well - so if the size is not exactly 4096 or if there are not enough or too many bytes then it should throw an exception
<oprypin>
that's what IO.read_bytes does
<FromGitter>
<kingsleyh> I need to create an IO? like a IO::Memory and put the bytes in it - and then read them out again ?
<oprypin>
yes
<FromGitter>
<kingsleyh> seems like a long way around since I already have the bytes
<FromGitter>
<kingsleyh> pity there is no bytes.to_memory_io
<FromGitter>
<kingsleyh> I think I will still have to chunk up the array
<FromGitter>
<vladfaust> You need to read until the bytes end :/
<FromGitter>
<kingsleyh> read_bytes should read all the bytes?
<oprypin>
usually bytes seems like a long way around since you already have the io
<FromGitter>
<dscottboggs_gitlab> on one hand the annotations make a nice API. But on the other hand, crystal's annotations syntax is super ugly and I don't have any idea how to make it less so. *Porque no los dos?*
<FromGitter>
<vladfaust> > on one hand the annotations make a nice API. But on the other hand, crystal's annotations syntax is super ugly and I don't have any idea how to make it less so. *Porque no los dos?* ⏎ ⏎ You know, it's ugly because it's compared to other Crystal syntaxes, which try to avoid special symbols - brackets etc. In Go this would look natively
<oprypin>
kingsleyh: IO is a stream, it advances the position, so i guess you can do `Array.new(1024) { io.read_bytes(...) }`
<FromGitter>
<dscottboggs_gitlab> that's true. I also wish crystal had the `or`, `and`, and `not` keywords. The one thing I found confusing about annotations is they seem to be applicable to instance vars and coming from python where they could only be applied to methods that definitely confused me. I should spend a little time learning how they work in crystal.
<FromGitter>
<kingsleyh> @oprypin this works thanks: `Array.new(4096) { io.read_bytes(UInt32, IO::ByteFormat::LittleEndian)}`
<FromGitter>
<vladfaust> Annotations allow composition, that's a strong point
<FromGitter>
<vladfaust> I.e. multiple annotations on a single variable
<FromGitter>
<Blacksmoke16> i dont see how you think annotations are ugly
<FromGitter>
<Blacksmoke16> compared to java maybe, but has to be unique syntax, not much you can do about it without a lot of work i imagine
<FromGitter>
<kingsleyh> @oprypin what is the equivalent in Crystal of `b.pack("V*")` where `b` is the Array(UInt32) of size 4096 - is it converting it back into Bytes?
<FromGitter>
<Blacksmoke16> however im not sure you can do what you were trying to there
<devil_tux>
also tried branch: master flag but it's sitting on 0.10.0 version, (will not update)
<FromGitter>
<vladfaust> Isn't that a bug?
<FromGitter>
<Blacksmoke16> not afaik, let me see if i can find it
<FromGitter>
<vladfaust> Cannot use `.instance_vars` in method definition
<FromGitter>
<vladfaust> Thanks, btw
<devil_tux>
anyone?
<FromGitter>
<Blacksmoke16> > Instance var information is only available inside methods. At the top level you never know when more instance vars are going to be added, and the compiler keeps them all and eventually solves them in one go considering all the type hierarchy
<FromGitter>
<Blacksmoke16> @vladfaust ^
<FromGitter>
<vladfaust> Could you give me a link to that, @Blacksmoke16
<FromGitter>
<vladfaust> And if I wanted to go annotations-way, i.e. get rid of `MODEL_ATTRIBUTES` data-constants, which @RX14 says are bad, I cannot define `@changes = HashOfInstanceVariablesTypes`
<devil_tux>
@vladfaust: can you try perhaps, pls?
<devil_tux>
the initial problem is on @crecto/crecto-admin (.25 support)