ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Fund Crystal's development: | GH: | Docs: | Gitter:
<FromGitter> <> 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``` []
<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 `"{foo:'2021-03-11'")`?
<FromGitter> <> @dan: are you using json or not?
<FromGitter> <Dan-Do> yeap, the string is from a unknown schema json
<FromGitter> <> @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> <> 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> <> don't use, 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 `` there
<FromGitter> <> 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 ` : 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 -]
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> <> @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> <> if using built in hash, you can use `, constant)` to at least be consistent across process invocations. but no guarantee for long-term compatibility across versions
<FromGitter> <> @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> <> @kingsleyh: what? no it doesnt
<FromGitter> <Blacksmoke16>
<FromGitter> <kingsleyh> ```code paste, see link``` []
<FromGitter> <> dont use icr lol
<FromGitter> <Blacksmoke16> that gets compiled twice, ☝️ March 11, 2021 4:36 PM (
<FromGitter> <kingsleyh> oh
<drakonis> is there any decent completion tooling?
<drakonis> vscode's is non functional here
<FromGitter> <Blacksmoke16> 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 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> <> @kingsleyh: just implement serialization into
<FromGitter> <> implementing JSON::Serializable with a custom to_json would also work
<FromGitter> <> oh the two suggestions are basically the same suggestion :D
sorcus has quit [Ping timeout: 268 seconds]
<FromGitter> <> 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:
<FromGitter> <kingsleyh> well it does come out different in icr - but haven't tested it outside icr
<FromGitter> <> @kingsleyh: delete icr
<FromGitter> <> @kingsleyh: haha yeah unfortunately Cannon has no guarantees. i think it requires same crystal version + same arch
<FromGitter> <> @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> <> would like to see it, anyway
<FromGitter> <> could be relevant?_?_
<FromGitter> <> what's interesting is the Byte format
<FromGitter> <> but the format is order dependent
<FromGitter> <> then
<FromGitter> <> writing a `to_json(builder)` remains my recommendation
<FromGitter> <> sorry I didn't follow the whole discussion, why the hash sha wanted?
<FromGitter> <> just need a permanently reproducible hash of some data structures
<FromGitter> <> to store in blockchain
<FromGitter> <> why #hash does not work?
<FromGitter> <Blacksmoke16> It's different on different invocations of the program
<FromGitter> <> ha?
<FromGitter> <> try it.
<FromGitter> <> `"a".hash`
<FromGitter> <> oprypin ( may be right: Crystalizer:ByteFormat could do it
<FromGitter> <> if your object structure does not change (i.e. you add/remove an ivar), it won't change
<FromGitter> <> well that's what I'd assume about json::serializable too
<FromGitter> <> but allegedly it changes (though no proof has been presented)
<FromGitter> <> at least, byte format will be much more efficient
<FromGitter> <kingsleyh> I will try it thanks
<FromGitter> <> 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> <> why? This is the order
<FromGitter> <> you mean, if you use another language?
<FromGitter> <> because in Crystal:
<FromGitter> <kingsleyh> yeah but in Crystal: alias SystemEndian = LittleEndian
<FromGitter> <kingsleyh> as long as that doens't change
<FromGitter> <> j8r ( @kingsleyh what lol of course that value is system dependent
<FromGitter> <> oprypin ( in crystal: `alias SystemEndian = LittleEndian`
<FromGitter> <> fix your lib to specify LittleEndian if you really mean it to be compatible
<FromGitter> <> compatible with what?
<FromGitter> <> itself
<FromGitter> <> 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> <> j8r ( check
<FromGitter> <> and other methods
<FromGitter> <> I don't understand?
<FromGitter> <> you can't say in crystal CONT = 18
<FromGitter> <> even though documentation says so
<FromGitter> <> If we follow your logic, `def write_bytes(object, format : IO::ByteFormat = IO::ByteFormat::SystemEndian)` should be changed?
sorcus has joined #crystal-lang
<FromGitter> <> that's just an alias
<FromGitter> <> the value of the alias is platform dependent
<FromGitter> <> currently all platforms happen to have the same value so on reality it currently happens to not be platform dependent
<FromGitter> <> How can it be? It is hard code in
<FromGitter> <> that will change when more platforms are supported
<FromGitter> <> Not sure I want to have my framework opinionated... People can easily chose that
<FromGitter> <> oh if they can choose that's ok
<FromGitter> <> of course they can! That's exactly like `write_bytes`
<FromGitter> <> 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> <> that's a bit like what the stdlib do
<FromGitter> <> ok but you're still defaulting to random
<FromGitter> <> do you or do you not have a feature that this lib can deserialize what this lib serialized?
<FromGitter> <> if you do, probably not good to intentionally not provide that by default
avane has quit [Quit: ZNC -]
<FromGitter> <> 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> <> do you or do you not have a feature that this lib can deserialize what this lib serialized?
<FromGitter> <> 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> <> it can do both what
<FromGitter> <> serialize and deserialize
<FromGitter> <> i thought ⏎ both deserialize and not deserialize