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
<FromGitter> <jrei:matrix.org> that's right, the difference is big corps can afford this
deavmi has joined #crystal-lang
<sorcus> naqvis: Are you here?
aquijoule_ has joined #crystal-lang
richbridger has quit [Ping timeout: 264 seconds]
<FromGitter> <naqvis> yeah sorcus
deavmi has quit [Read error: Connection reset by peer]
DTZUZU has quit [Ping timeout: 260 seconds]
ua_ has quit [Excess Flood]
DTZUZU has joined #crystal-lang
Flipez has quit [Quit: Ping timeout (120 seconds)]
Flipez has joined #crystal-lang
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 272 seconds]
f1reflyylmao is now known as f1refly
deavmi has joined #crystal-lang
SuperFamicom has joined #crystal-lang
<SuperFamicom> quit
SuperFamicom has quit [Quit: Lost terminal]
SuperFamicom[m] has joined #crystal-lang
ua has joined #crystal-lang
_ht has joined #crystal-lang
fifr` has quit [Ping timeout: 265 seconds]
fifr` has joined #crystal-lang
hendursaga has joined #crystal-lang
andremed- has joined #crystal-lang
hendursa1 has quit [Ping timeout: 268 seconds]
andremedeiros has quit [Ping timeout: 260 seconds]
andremed- is now known as andremedeiros
sz0 has joined #crystal-lang
sz0 has quit [Max SendQ exceeded]
sz0 has joined #crystal-lang
sz0 has quit [Max SendQ exceeded]
sz0 has joined #crystal-lang
sz0 has quit [Max SendQ exceeded]
sz0 has joined #crystal-lang
sz0 has quit [Max SendQ exceeded]
sz0 has joined #crystal-lang
postmodern has quit [Quit: Leaving]
tungki has joined #crystal-lang
tungki has quit [Ping timeout: 260 seconds]
<FromGitter> <Dan-Do> How to use this method? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=604a0cc6823b6654d29b11a7]
<FromGitter> <naqvis> use where? and what's your intention?
<FromGitter> <naqvis> do you need to parse date time?
<FromGitter> <Dan-Do> Yes, I want to parse date from a string, I know that we can use Time.parse, but curious how to use the above function :)
<FromGitter> <Dan-Do> Can it just be simple as `Time.new("{foo:'2021-03-11'")`?
<FromGitter> <oprypin:matrix.org> @dan: are you using json or not?
<FromGitter> <Dan-Do> yeap, the string is from a unknown schema json
<FromGitter> <oprypin:matrix.org> @dan: do you at this point have a string with just the time expr, or is it still JSON?
<FromGitter> <Dan-Do> a string
<FromGitter> <oprypin:matrix.org> then you don't need a json-specific helper. why would you want to put it back into JSON only to tell it to unwrap it again
<FromGitter> <oprypin:matrix.org> don't use Time.new, copy what's inside its implementation directly
<FromGitter> <Dan-Do> ah, I just curious how to use that method :)
<FromGitter> <Dan-Do> I don't see any `Time.new` there
<FromGitter> <oprypin:matrix.org> a json::serializable object having a Time field will be parsed from the string as part of a higher-level json parsing
<FromGitter> <Dan-Do> okay, as I understand, the `Time.new(pull : JSON::PullParser)` can be only used in a `from_json`, right?
<FromGitter> <Dan-Do> we cannot call it directly as `Time.parse`
<FromGitter> <naqvis> `Time::Format::ISO_8601_DATE_TIME.parse(string)` you can use in this way
<FromGitter> <naqvis> where `string` is string containing the specific formatted datetime
<FromGitter> <Dan-Do> @naqvis Thank you :)
PixeLInc_ has joined #crystal-lang
maxpowa_ has joined #crystal-lang
andremed- has joined #crystal-lang
andremedeiros has quit [Ping timeout: 256 seconds]
PixeLInc has quit [Ping timeout: 256 seconds]
duane has quit [Ping timeout: 256 seconds]
baweaver has quit [Ping timeout: 256 seconds]
sagax has quit [Ping timeout: 256 seconds]
maxpowa has quit [Ping timeout: 256 seconds]
commavir has quit [Ping timeout: 256 seconds]
maxpowa_ is now known as maxpowa
andremed- is now known as andremedeiros
commavir_ has joined #crystal-lang
commavir_ is now known as commavir
teardown_ has joined #crystal-lang
teardown has quit [Remote host closed the connection]
avane has quit [Quit: ZNC - https://znc.in]
avane has joined #crystal-lang
sagax has joined #crystal-lang
aquijoule_ has quit [Remote host closed the connection]
aquijoule_ has joined #crystal-lang
_ht has quit [Remote host closed the connection]
ua has quit [Read error: Connection reset by peer]
ua has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
<FromGitter> <kingsleyh> evening - is there anythign in Crystal that I can use to turn my crystal object into a canonical hash? I was using sha256(my_object.to_json) but it seems that the to_json might not always be coming out in the same order affecting the hashing. I would like to guarantee my hash always comes out the same
<FromGitter> <Blacksmoke16> try `obj.hash`
<FromGitter> <oprypin:matrix.org> @kingsleyh: sort before calling `to_json`
<FromGitter> <kingsleyh> obj.hash doesn't look like it will work
<FromGitter> <kingsleyh> I guess I have to write something myself that takes the hash and processes it - it has many nested objects - so will have to process all of them
<FromGitter> <Blacksmoke16> ah right, in your case you'd want the hash to be equal if the objs are equal
<FromGitter> <oprypin:matrix.org> if using built in hash, you can use https://github.com/crystal-lang/crystal/blob/7aa9e98a195a2da63f703be36e5694074a1179a9/src/crystal/hasher.cr#L85 `Hasher.new(constant, constant)` to at least be consistent across process invocations. but no guarantee for long-term compatibility across versions
<FromGitter> <oprypin:matrix.org> @kingsleyh: why do you guess that?
<FromGitter> <Blacksmoke16> afaik `#hash` would be diff for diff instances of equal objs
<FromGitter> <kingsleyh> yeah each call to crystal .hash for the same string gives different results
<FromGitter> <oprypin:matrix.org> @kingsleyh: what? no it doesnt
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/aj5a
<FromGitter> <kingsleyh> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=604a8de395e23446e42ae1d5]
<FromGitter> <oprypin:matrix.org> dont use icr lol
<FromGitter> <Blacksmoke16> that gets compiled twice, ☝️ March 11, 2021 4:36 PM (https://gitter.im/crystal-lang/crystal?at=604a8d49d71b6554cd39a8cc)
<FromGitter> <kingsleyh> oh
<drakonis> is there any decent completion tooling?
<drakonis> vscode's is non functional here
<FromGitter> <Blacksmoke16> https://github.com/elbywan/crystalline prob your best bet
<FromGitter> <Blacksmoke16> @kingsleyh the hash value will be the same within the same invocation of the program, but isn't guaranteed to be the same across multiple invocatiosn
<FromGitter> <Blacksmoke16> as @oprypin:matrix.org pointed out
fifr` has quit [Ping timeout: 260 seconds]
<FromGitter> <Blacksmoke16> whats the use case of needing this value?
<FromGitter> <kingsleyh> my blockchain project - the block is hashed and set in the previous_hash field - so each block prev_hash must match the value of the previous block to hash
<FromGitter> <kingsleyh> currently every now and again - the hash is different to the expected
<FromGitter> <kingsleyh> which seems to be due to the block.to_json
<FromGitter> <kingsleyh> I need a sha256 hash of the block that always produces the same hash for the same block
<FromGitter> <kingsleyh> if the to_json decides to come out in a different order then the hash is different
<FromGitter> <Blacksmoke16> as oprypin said, could you just ensure the data is sorted before calling `.to_json`
<FromGitter> <Blacksmoke16> like an explicit sort
<FromGitter> <kingsleyh> yeah - I can try - I have many custom data types and a lot of nesting - so it might be that I just need to write a new serializer that is canonical
<FromGitter> <Blacksmoke16> 😬 sounds like a pita
<FromGitter> <kingsleyh> I'm going to experiment with turning the object into a map and sorting it and turning it into a string
<FromGitter> <oprypin:matrix.org> @kingsleyh: just implement serialization into https://crystal-lang.org/api/JSON/Builder.html
<FromGitter> <oprypin:matrix.org> implementing JSON::Serializable with a custom to_json would also work
<FromGitter> <oprypin:matrix.org> oh the two suggestions are basically the same suggestion :D
sorcus has quit [Ping timeout: 268 seconds]
<FromGitter> <oprypin:matrix.org> i also would like to see the claim backed up - the claim that to_json can come out in a different order. i cant imagine how, unless a `Hash` is involved
<FromGitter> <kingsleyh> the name of this made it seem like it would be canonical but don't think it is: https://github.com/Papierkorb/cannon
<FromGitter> <kingsleyh> @oprypin:matrix.org well it does come out different in icr - but haven't tested it outside icr
<FromGitter> <oprypin:matrix.org> @kingsleyh: delete icr
<FromGitter> <oprypin:matrix.org> @kingsleyh: haha yeah unfortunately Cannon has no guarantees. i think it requires same crystal version + same arch
<FromGitter> <oprypin:matrix.org> @kingsleyh: but i shouldnt be so dismissive of icr. if to_json is coming out different, it doesnt matter that it's icr, it just shouldnt come out different anyway
<FromGitter> <oprypin:matrix.org> would like to see it, anyway
<FromGitter> <oprypin:matrix.org> https://github.com/j8r/crystalizer could be relevant?_?_
<FromGitter> <oprypin:matrix.org> what's interesting is the Byte format
<FromGitter> <jrei:matrix.org> but the format is order dependent
<FromGitter> <oprypin:matrix.org> then
<FromGitter> <oprypin:matrix.org> writing a `to_json(builder)` remains my recommendation
<FromGitter> <jrei:matrix.org> sorry I didn't follow the whole discussion, why the hash sha wanted?
<FromGitter> <oprypin:matrix.org> just need a permanently reproducible hash of some data structures
<FromGitter> <oprypin:matrix.org> to store in blockchain
<FromGitter> <jrei:matrix.org> why #hash does not work?
<FromGitter> <Blacksmoke16> It's different on different invocations of the program
<FromGitter> <jrei:matrix.org> ha?
<FromGitter> <oprypin:matrix.org> try it.
<FromGitter> <oprypin:matrix.org> `"a".hash`
<FromGitter> <jrei:matrix.org> oprypin (https://matrix.to/#/@oprypin:matrix.org) may be right: Crystalizer:ByteFormat could do it
<FromGitter> <jrei:matrix.org> if your object structure does not change (i.e. you add/remove an ivar), it won't change
<FromGitter> <oprypin:matrix.org> well that's what I'd assume about json::serializable too
<FromGitter> <oprypin:matrix.org> but allegedly it changes (though no proof has been presented)
<FromGitter> <jrei:matrix.org> at least, byte format will be much more efficient
<FromGitter> <kingsleyh> I will try it thanks
<FromGitter> <jrei:matrix.org> note that is has limitations regarding to dynamic data structures, like Hash and Array
<FromGitter> <kingsleyh> this is suspicious: @format : IO::ByteFormat = IO::ByteFormat::SystemEndian,
<FromGitter> <kingsleyh> not sure if that is going to be canonical across systems
<FromGitter> <jrei:matrix.org> why? This is the order
<FromGitter> <jrei:matrix.org> you mean, if you use another language?
<FromGitter> <jrei:matrix.org> because in Crystal: https://crystal-lang.org/api/master/IO/ByteFormat/SystemEndian.html
<FromGitter> <kingsleyh> yeah but in Crystal: alias SystemEndian = LittleEndian
<FromGitter> <kingsleyh> as long as that doens't change
<FromGitter> <oprypin:matrix.org> j8r (https://matrix.to/#/@jrei:matrix.org): @kingsleyh what lol of course that value is system dependent
<FromGitter> <jrei:matrix.org> oprypin (https://matrix.to/#/@oprypin:matrix.org): in crystal: `alias SystemEndian = LittleEndian`
<FromGitter> <oprypin:matrix.org> fix your lib to specify LittleEndian if you really mean it to be compatible
<FromGitter> <jrei:matrix.org> compatible with what?
<FromGitter> <oprypin:matrix.org> itself
<FromGitter> <jrei:matrix.org> I really depends of what protocol you want to do
<FromGitter> <kingsleyh> ok anyway thanks for the pointers I have some things to investigate now :)
<FromGitter> <oprypin:matrix.org> j8r (https://matrix.to/#/@jrei:matrix.org): check https://crystal-lang.org/api/0.36.1/Signal.html
<FromGitter> <jrei:matrix.org> and other methods
<FromGitter> <jrei:matrix.org> I don't understand?
<FromGitter> <oprypin:matrix.org> you can't say in crystal CONT = 18
<FromGitter> <oprypin:matrix.org> even though documentation says so
<FromGitter> <jrei:matrix.org> If we follow your logic, `def write_bytes(object, format : IO::ByteFormat = IO::ByteFormat::SystemEndian)` should be changed?
sorcus has joined #crystal-lang
<FromGitter> <jrei:matrix.org> that's just an alias
<FromGitter> <oprypin:matrix.org> the value of the alias is platform dependent
<FromGitter> <oprypin:matrix.org> currently all platforms happen to have the same value so on reality it currently happens to not be platform dependent
<FromGitter> <jrei:matrix.org> How can it be? It is hard code in https://github.com/crystal-lang/crystal/blob/7aa9e98/src/io/byte_format.cr#L120
<FromGitter> <oprypin:matrix.org> that will change when more platforms are supported
<FromGitter> <jrei:matrix.org> Not sure I want to have my framework opinionated... People can easily chose that
<FromGitter> <oprypin:matrix.org> oh if they can choose that's ok
<FromGitter> <jrei:matrix.org> of course they can! That's exactly like `write_bytes`
<FromGitter> <oprypin:matrix.org> sorry then. i made a bad assumption just based on that comment
deavmi has quit [Quit: Eish! Load shedding.]
<raz> wouldn't it make sense to default to big or little tho? defaulting to "random" seems like a footgun
<FromGitter> <jrei:matrix.org> that's a bit like what the stdlib do
<FromGitter> <oprypin:matrix.org> ok but you're still defaulting to random
<FromGitter> <oprypin:matrix.org> do you or do you not have a feature that this lib can deserialize what this lib serialized?
<FromGitter> <oprypin:matrix.org> if you do, probably not good to intentionally not provide that by default
avane has quit [Quit: ZNC - https://znc.in]
<FromGitter> <jrei:matrix.org> I just provide the default use by IO::ByteFormat
<raz> well, i guess in practice it would be fairly easy to notice and fix. but yea, i'd kinda expect a serialization lib to deserialize its data on all platforms by default :) (or a warning sticker in the readme)
<FromGitter> <oprypin:matrix.org> do you or do you not have a feature that this lib can deserialize what this lib serialized?
<FromGitter> <jrei:matrix.org> it can do both
* raz shines desk lamp into jreis face
<raz> hmm, he's still trying to weasel out!
avane has joined #crystal-lang
<FromGitter> <oprypin:matrix.org> it can do both what
<FromGitter> <jrei:matrix.org> serialize and deserialize
<FromGitter> <oprypin:matrix.org> i thought ⏎ both deserialize and not deserialize