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
Starfoxxes has quit [Ping timeout: 245 seconds]
Starfoxxes has joined #crystal-lang
ur5us has quit [Ping timeout: 264 seconds]
notzmv has quit [Ping timeout: 240 seconds]
olbat[m] has quit [Quit: Client limit exceeded: 20000]
hightower2 has joined #crystal-lang
ur5us has joined #crystal-lang
Chillfox has quit [Ping timeout: 260 seconds]
<FromGitter> <paulocoghi> Hello Crystal community! ⏎ ⏎ On `Time` api, is it possible to directly read the `Int64` for seconds from epoch and `Int32` for nanoseconds?
olbat[m] has joined #crystal-lang
ur5us has quit [Ping timeout: 240 seconds]
<straight-shoota> Not really. You can access the ivar as `time.@seconds` but that's not a public API.
<straight-shoota> I proposed exposing a method for that, but it was not accepted: https://github.com/crystal-lang/crystal/pull/6661 You might leave your use case there, maybe it can be considered
<straight-shoota> Time#nanosecond exposes the nanosecond component directly, though
<FromGitter> <paulocoghi> My use case is to create unique timestamps which include nano seconds to avoid collision when creating millions of timestamps per second
<FromGitter> <paulocoghi> They will be use in a database similar to couchdb/pouchdb where the timestamp allows offline insertions on different nodes, with collision-free synchronizations after the creation
^raz^ has quit [Quit: *fump*]
raz has joined #crystal-lang
raz has quit [Changing host]
raz has joined #crystal-lang
hightower2 has quit [Ping timeout: 256 seconds]
<yxhuvud> birthday paradox means you have no guarantee of uniqueness though.
<FromGitter> <paulocoghi> I will read about it right now! Thanks!
<yxhuvud> or well, it wouldn't be good enough for uniqueness guarantee anyhow, but birthday paradox mean you will have duplicates *often*.
<FromGitter> <paulocoghi> Now I understand what you mean. In my understanding, the statistical chance of collision when working with nanosecond resolution is only considerable when passing the 999 million insertions per second, which would be more than one insertion per nanosecond
<FromGitter> <paulocoghi> But it seems that my thinking may be an ingenuous one xD
<FromGitter> <Blacksmoke16> Wouldn't it be better to use UUIDs ⏎ ?
<FromGitter> <christopherzimmerman> Yes, if he generated 1 billion records a second for a hundred years, with sufficient entropy he’d have a 50% chance of seeing a collision.
hightower2 has joined #crystal-lang
<FromGitter> <paulocoghi> xD
<FromGitter> <paulocoghi> Researching a bit, the fastest UUID library I could find by now is WUID (https://github.com/edwingeng/wuid), where it's possible to generate from 100M to 200M id's per second. Also, it's only capable of such speed because it's not fully UUID compliant (the fastest fully compliant library I found provides around 20M id's per second) ⏎ ⏎ If the first mentioned library is the world's fastest, using UUID
<FromGitter> ... would not help to ensure reliability over 1 billion records a second, since the approach is slower by itself than the desired threshold
<FromGitter> <Blacksmoke16> do you really need over 1b records a second?
<FromGitter> <paulocoghi> I do not need. Maybe a user of our database from the future xD xD
<FromGitter> <paulocoghi> With the current constraints, I believe our database will not be able to surpass the 1M creations per second on the near future :)
ua_ has quit [Read error: Connection reset by peer]
ua_ has joined #crystal-lang
yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
yxhuvud has joined #crystal-lang
Peter0x41 is now known as Peter0x44
<FromGitter> <christopherzimmerman> Is your database going to be able to handle constant inserts of 1B records a second?
<FromGitter> <christopherzimmerman> That seems like it's going to be a far more limiting factor than generating UUIDs.
notzmv has joined #crystal-lang
<FromGitter> <paulocoghi> > Is your database going to be able to handle constant inserts of 1B records a second? ⏎ ⏎ No
<FromGitter> <paulocoghi> > That seems like it's going to be a far more limiting factor than generating UUIDs. ⏎ ⏎ You are right
<riza> @paulocoghi - I haven't yet seen a port of this to crystal, but the twitter snowflake ID generation system is a robust, scaleable, distributed ID generation system that you might find interesting. Quick google popped up a bunch of results, eg https://github.com/RobThree/IdGen
<riza> we used a sql-native varient of snowflake at one company a few years back and it was both completely unnecessary and wonderfully capable
taskylizard has joined #crystal-lang
<FromGitter> <paulocoghi> Thanks, @riza! IdGen is really interesting, timestamp-based *but* more solid than my idea :)
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
<riza> in my memory the timestamp rolls over every millisecond, so each server generating IDs has 10+12 bits of entropy for every milli
<riza> well, the 10 bits is usually some combination of fixed server_id and region identifier and such
<riza> <timestamp in millis><server id><12 bit sequencial>, and the sequencial resets at every milli
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
taskylizard has quit [Changing host]
taskylizard has joined #crystal-lang
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
taskylizard has quit [Changing host]
taskylizard has joined #crystal-lang
taskylizard has quit [Read error: Connection reset by peer]
taskylizard has joined #crystal-lang
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
avane_ is now known as avane
taskylizard has quit [Changing host]
taskylizard has joined #crystal-lang
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
<FromGitter> <shomodj> There is also this https://github.com/rs/xid
sorcus has quit [Ping timeout: 246 seconds]
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
taskylizard has joined #crystal-lang
taskylizard has quit [Changing host]
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
sorcus has joined #crystal-lang
taskylizard has quit [Remote host closed the connection]
taskylizard has joined #crystal-lang
ur5us has joined #crystal-lang
Guest95 has joined #crystal-lang
<Guest95> hello
<Guest95> I'm dumping a hash to JSON, and some of the values (like "   ") are written as "\"   \"" - is there a way to avoid this?
<FromGitter> <Blacksmoke16> i.e. like `{"foo":"Bar \" \" Baz"}`?
<Guest95> yes, something like that
<FromGitter> <Blacksmoke16> those are required, otherwise it would be invalid JSON since the `"` would conflict with the opening/closing string `"`
<Guest95> but the original value is "   " - why can't the JSON output be "    " ?
<Guest95> I mean, the quotes are not part of the value right?
<Guest95> inner quotes, sure - but not terminal ones
<FromGitter> <Blacksmoke16> you mean like `pp " ".to_json`?
<Guest95> I don't know what pp is
<Guest95> the value of the string is "   " (3 spaces) and the output is "\"   \"'
<FromGitter> <Blacksmoke16> `"\" \""` is what it outputs
<Guest95> yes, that
<FromGitter> <Blacksmoke16> how are you printing/looking at it? because in this context you see the `\"` because its enclosed in another set of quotes
<FromGitter> <Blacksmoke16> whereas if you just did `puts` you wouldn't see it
<Guest95> I'm writing specs to validate my JSON and the value doesn't correspond to what I read
<Guest95> because of the extra \"
<FromGitter> <Blacksmoke16> try doing like `my_obj.to_json.should eq %({"foo": " "})`
<FromGitter> <Blacksmoke16> if you have a playground link example that would be super helpful as well
<Guest95> what if the two values are variables?
<Guest95> `expected_label.should eq(operands)`
<Guest95> Expected: "\"   \""
<Guest95>             got: "   "
<FromGitter> <Blacksmoke16> how are you setting the value of `operands`?
<Guest95> `operands = instruction["operands_summary"].as_s`
<FromGitter> <Blacksmoke16> er `expected_label`
<Guest95> `expected_label = build_label(state, decoded_instruction)`
<Guest95> here's `build_label` https://carc.in/#/r/c8hp
<FromGitter> <Blacksmoke16> are you maybe comparing the raw JSON string to the JSON string's value?
<Guest95> is that what `.as_s` does?
<Guest95> this is my spec https://carc.in/#/r/c8hq
<FromGitter> <Blacksmoke16> if `operands_summary` is a json string yea
<Guest95> hmm ok
HumanG33k has quit [Quit: WeeChat 3.0]
<FromGitter> <Blacksmoke16> https://carc.in/#/r/c8hs
<Guest95> ok, makes sense
<Guest95> thanks
<FromGitter> <Blacksmoke16> https://carc.in/#/r/c8ht
<FromGitter> <Blacksmoke16> 👍
<Guest95> yeah, but in my case the JSON is part of the string I'm comparing
<FromGitter> <Blacksmoke16> `" ".to_json != " "`
<FromGitter> <Blacksmoke16> but `" ".to_json == %(" ")` and `" ".to_json == "\" \""`
<FromGitter> <Blacksmoke16> so might just need to update the expected string to be the expected *json* string, not the json string's value i that makes sense
<FromGitter> <Blacksmoke16> if that*
<Guest95> so `operands` can contain a JSON string or something like "L00,#0a [FALSE] cbb1" so fixed it for now with `operands = JSON.parse(operands) rescue operands`
<Guest95> thanks for the pointer!
<FromGitter> <Blacksmoke16> mm that feels like a hack
<Guest95> it is :D
<Guest95> I can do it better, but for now I'm unblocked
<FromGitter> <Blacksmoke16> 👍 fair enough
<Guest95> it's possible to know if it's text or not
<Guest95> ok, so failing again with a certain output https://carc.in/#/r/c8hy
<Guest95> isn't a single \" within quotes allowed?
<FromGitter> <Blacksmoke16> thats not valid json
<Guest95> so there's no way to encode a single " within a string
<Guest95> hmm I think I'll use base64 for strings
<Guest95> since they have weird characters inside
<FromGitter> <Blacksmoke16> hmm, there *should* be a way
<FromGitter> <Blacksmoke16> sec
<Guest95> hmm, ```{
<Guest95>     "value": "\"Tomorrow never yet"
<Guest95> }``` is valid JSON
<FromGitter> <Blacksmoke16> `JSON.parse "\"\\\"Tomorrow never yet\""` is the proper way to handle this
<FromGitter> <Blacksmoke16> outer most `"` represent the JSON string itself
<FromGitter> <Blacksmoke16> inner `\"` represent the raw string value of the JSON string
<FromGitter> <Blacksmoke16> `\\\"` represents an escaped `"` within the raw JSON string's value
<FromGitter> <Blacksmoke16> and will output `"Tomorrow never yet`
<Guest95>  damn, good to know thanks
<Guest95> I think I'll just b64 the strings - seems easier
<FromGitter> <Blacksmoke16> mmk
sagax has quit [Quit: Konversation terminated!]
Guest95 has quit [Quit: Client closed]
sagax has joined #crystal-lang