jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | 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
deavmi has quit [Ping timeout: 256 seconds]
deavmi has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
_whitelogger has joined #crystal-lang
f1refly has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 272 seconds]
<FromGitter> <Blacksmoke16> wow, code is super ugly but this works now
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f28cbed6334d26a7e722cd0]
<FromGitter> <Blacksmoke16> but probably very brittle
<FromGitter> <Blacksmoke16> `SELECT t0."id" AS c1, t0."name" AS c2, t0."alive" AS c3, t5."id" AS c4, t5."color" AS c6, t5."user_id" AS c7 FROM "users" t0 LEFT JOIN "settings" t5 ON t5."user_id" = t0."id" WHERE t0."id" = $1` if you were wondering, yes you can have one obj consume a result set, then pass that on to another, assuming columns are selected in correct order
zorp has quit [Ping timeout: 264 seconds]
alexherbo2 has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter> <guglielmocg_gitlab> Hello everyone, first post on the crystal board. ⏎ In Ruby I can use YAML.load to interpret a correctly formatted string as a hash. I would like to know if Crystal has such a functionality where it can turn a string like "{key: value}" into an object {"key": "value"}
<FromGitter> <naqvis> @guglielmocg_gitlab Welcome. Are you asking to load YAML to `Hash`?
<FromGitter> <naqvis> so if you are asking of transforming yaml string to Hash then you can try sth like ⏎ ⏎ ```require "yaml" ⏎ YAML.parse("{key: value}" ).as_h? # => {"key" => "value"}``` [https://gitter.im/crystal-lang/crystal?at=5f29127e14c413356f559f3f]
<FromGitter> <guglielmocg_gitlab> ah ok that's perfect!
<FromGitter> <guglielmocg_gitlab> that's exactly what I need
<FromGitter> <naqvis> 👍
yxhuvud has quit [Ping timeout: 240 seconds]
yxhuvud has joined #crystal-lang
postmodern has quit [Quit: Leaving]
lunarkitty has quit [Ping timeout: 272 seconds]
lunarkitty has joined #crystal-lang
<FromGitter> <scriptmaster> Hi, I am trying to do some querying on a postgres db via crystal, and I see this: In examples/shoddy_psql.cr:2:1 ⏎ ⏎ 2 | require "readline" ⏎ ⏎ ``` ^``` ... [https://gitter.im/crystal-lang/crystal?at=5f293eb447738110233e9cd4]
<FromGitter> <scriptmaster> name: pg ⏎ version: 0.21.1 ⏎ ⏎ dependencies: ⏎ db: ... [https://gitter.im/crystal-lang/crystal?at=5f293ec436563560f2c140a8]
<FromGitter> <scriptmaster> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f293f050ff358499bd35911]
<FromGitter> <scriptmaster> im trying this: https://github.com/crystal-community/icr/issues/114
<FromGitter> <scriptmaster> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f2940c80ff358499bd35d47]
<FromGitter> <scriptmaster> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f29415303d73b60ee66758c]
zorp has joined #crystal-lang
<FromGitter> <scriptmaster> I had to do `brew reinstall openssl` and then `export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"`
<FromGitter> <asterite> postmodern: there's only one type of enum in Crystal, there's no such thing as a "C enum" and "Crystal enum" (there used to be a difference but not anymore). For LLVM we use enums, and these are declared outside of the "lib" namespace because they are user-facing too
zorp has quit [Ping timeout: 256 seconds]
<FromGitter> <throwaway4rust> I am trying to run some crystal project and I constantly get random "failed to update" when I do shards install
<FromGitter> <throwaway4rust> by random I mean it fetches different pkgs and the pkgs fail randomly
<FromGitter> <Blacksmoke16> can you share the error?
<FromGitter> <throwaway4rust> That's all I see
<FromGitter> <Blacksmoke16> try `shards install -v`?
<FromGitter> <Blacksmoke16> and what crystal/shards version?
<FromGitter> <throwaway4rust> doing that
<FromGitter> <throwaway4rust> crystal is latest and shards I needs to check
<FromGitter> <throwaway4rust> I am btw trying to run that microgit posted on reddit
<FromGitter> <Blacksmoke16> theres a shard.lock so it should work
<FromGitter> <throwaway4rust> Error target lucky.gen.migration failed to compile: ⏎ Showing last frame. Use --error-trace for full trace. ⏎ ⏎ In lib/dexter/src/dexter/log/context.cr:1:7 ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5f2967d947738110233f1523]
<FromGitter> <scriptmaster> the command is called shards (crystal shards of a gem) and the file is called shard.lock and shard.yml - shard install would have been better or shards.yml and shards.lock would have been way better..
<FromGitter> <scriptmaster> and there isn't a shards add ? I had to put that in the .yml everytime..
<FromGitter> <Blacksmoke16> not atm, was an issue/pr about it iirc
<FromGitter> <Blacksmoke16> @throwaway4rust thats a compile error
<FromGitter> <throwaway4rust> seems so
<FromGitter> <Blacksmoke16> is it a postinstall step?
<FromGitter> <throwaway4rust> Building: lucky.gen.migration
<FromGitter> <throwaway4rust> yeah
<FromGitter> <Blacksmoke16> yea i dunno, prob best to drop into the lucky gitter
<FromGitter> <Blacksmoke16> or tell the guy on reddit
<FromGitter> <throwaway4rust> ill try higher version of dexter
<FromGitter> <throwaway4rust> i cant see it has been reported already
<FromGitter> <throwaway4rust> i can*
<FromGitter> <Blacksmoke16> 👍 could have been he was working with a locked version that didnt support `0.35.x`
<FromGitter> <Blacksmoke16> maybe try an update
Dreamer3 has joined #crystal-lang
<FromGitter> <throwaway4rust> Does having a powerful Ryzen or Threadripper actually help with compile speeds for LLVM languages like Crystal and Rust?
<FromGitter> <Blacksmoke16> crystal is single threaded when compiling so prob not
<FromGitter> <j8r> Single core is the most important yes
<FromGitter> <throwaway4rust> Ah so the compiler would have to be parallelized
<FromGitter> <throwaway4rust> and that's probably pretty hard to do right?
<FromGitter> <Blacksmoke16> probably yea
deavmi has quit [Quit: Eish! Load shedding.]
deavmi has joined #crystal-lang
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
zorp has joined #crystal-lang
<FromGitter> <asterite> the codegen (LLVM) phase is done in parallel in a bunch of threads, so the answer is yes (for that part)
<FromGitter> <j8r> Is there any better way to know what Integer type an Enum has? https://carc.in/#/r/9hte
<FromGitter> <Blacksmoke16> prob define some class method on it?
<FromGitter> <wontruefree> this is a crazy question but I am looking for a blog post that I thought was on crystal-lang.org. It was about named parameters and there was an example of positional and named arguments and how crystal handles them
<FromGitter> <Blacksmoke16> wasnt that part of a talk ary gave
<FromGitter> <wontruefree> it might have been
<FromGitter> <wontruefree> hmmm I thought I might know what talk but I dont see it
<FromGitter> <Blacksmoke16> that one?
<FromGitter> <wontruefree> I was looking through those slides
<FromGitter> <wontruefree> but the feature I am looking for is named args + multi dispatch
<FromGitter> <wontruefree> hmmmm I am not seeing the think I am looking for. But I think I have enough to put this together
<FromGitter> <asterite> there's a slide "Named arguments. What about multi-dispatch?": https://youtu.be/5rpZOtcCHtk?t=1736
zorp has quit [Ping timeout: 240 seconds]
deavmi has quit [Ping timeout: 240 seconds]
deavmi has joined #crystal-lang
Dreamer3 has quit [Quit: Leaving...]
DTZUZU_ has joined #crystal-lang
DTZUZU has quit [Ping timeout: 264 seconds]
duane has quit [Read error: No route to host]
zorp has joined #crystal-lang
<FromGitter> <j8r> Does someone is familiar with byte protocols?
<FromGitter> <j8r> Can it makes sense to have a String field with only 0 bytes be considered nil?
<raz> i'd say that depends very much on what your protocol looks like
<raz> (and why you're homebrewing one yourself to begin with, rather than going with protobuf or such)
<FromGitter> <j8r> I'm extending https://github.com/j8r/crystalizer to allow [de]serializing to/from bytes
<FromGitter> <j8r> I think I will not deal with unions at all
<FromGitter> <j8r> overall a protocol has to have clearly, unambiguously typed fields
<raz> hmm, shouldn't nil be its own type then?
<raz> making it an empty string feels weird to me (but no idea if it'd make a difference for anything relevant)
<FromGitter> <j8r> empty string sounds logical.
<raz> how do you serialize? <type><size><body>?
<FromGitter> <j8r> the idea is to have an annotation for the String/Bytes size
<FromGitter> <j8r> serializing iterates over each ivar of an object, in the order
<oprypin> what's an efficient way to iterate over a Hash in sorted order
<oprypin> surely not .to_a.sort!.each
<FromGitter> <Blacksmoke16> sorted in which way? hash is sorted based on insert order
<oprypin> oh excuse me `.to_a.sort_by!(&.[0]).each`
<FromGitter> <j8r> probably sorting keys
<oprypin> i'd prefer to sort the hash itself once, of course
<raz> j8r: hmm. not sure about that particular case. but i think it might be worth taking a peek at protobuf (and perhaps the ser-formats of other languages) for general inspiration. lots of prior art out there, and
<raz> not all of it worth reinventing ;)
<FromGitter> <j8r> yeah raz, thanks
<FromGitter> <j8r> by the way I use the stdlib https://crystal-lang.org/api/master/IO/ByteFormat.html
<FromGitter> <j8r> (through `IO#write` and `IO#read`
<oprypin> thts nice
<raz> yap i think that prob makes sense.
<raz> maybe it could be even faster if it had direct compiler support, but that's beyond my knowledge horizon
<raz> (but the format would prob be the same anyway)
<FromGitter> <j8r> if the field is 3 and the string is `"a"`, the bytes would be `Bytes[97, 0, 0]` - logic. I don't see any other way to do. So an empty string will be `Bytes[0, 0, 0]`
<FromGitter> <j8r> AFAIK msgpack and protobuf don't really support unions
<oprypin> j8r, no msgpack has to, json is union-like
<oprypin> its just not arbitrary unions
<FromGitter> <j8r> I searched union :/
<FromGitter> <j8r> it's another name?
<oprypin> what
<FromGitter> <j8r> you said msgpack has to support unions
<oprypin> it just has to support this explicitly defined union
<FromGitter> <j8r> ... it justs support multiple formats
<oprypin> yea thats a union
<FromGitter> <j8r> But not a field that can either, say Int32 or Float64
<FromGitter> <j8r> sorry that's what I was talking ;)
<oprypin> how about a field that can either "positive fixint" or "float 64" or any other from that list
<FromGitter> <j8r> msgpack is self-describing right?
<FromGitter> <j8r> that's just json more optimized
<FromGitter> <j8r> and also, it transmits the type
<FromGitter> <j8r> this allows to have unions then, right
<FromGitter> <j8r> In my case, using only the stdlib, I don't build a protocol - not really. The key and type are not transmitted
<oprypin> j8r, but wait, when you were serializing to json and yaml, the key (and maybe type) were transmitted
<FromGitter> <j8r> yes
<FromGitter> <j8r> here I encode to bytes, using https://crystal-lang.org/api/master/IO/ByteFormat.html, directly
<oprypin> https://github.com/Papierkorb/cannon 😔😔😔😔😔😔😔😔😔😔😔😔😔😔😔😔
<oprypin> such a huge loss i still cant get over it
<FromGitter> <j8r> sure, but I have a JS client, which uses things like https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/Uint8Array
<FromGitter> <j8r> thanks for the reference, i will dig into it to take some inspiration
<oprypin> j8r, shouldnt it be a different library then
<oprypin> if one part of your lib specifies field names and types and another one requires them
<oprypin> actually.. do you support serializing arbirary structures like json does or not?
<oprypin> i mean stdlib's json serializable
DTZUZU has joined #crystal-lang
zorp has quit [Ping timeout: 240 seconds]
<FromGitter> <j8r> not arbitrary, the schema need to be known both by the client and server
DTZUZU_ has quit [Ping timeout: 256 seconds]
<FromGitter> <j8r> really just the stdlib is used. For instance, if an object has `@ivar = 1` and `@other = 12.4`, an IO::Memory will be created (from your advice), @ivar will be converter to bytes with `io.write_bytes @ivar`, same for @other.
<FromGitter> <j8r> I just had few thing like filling with `0` too short strings, to fit the field size, things like that
duane has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 256 seconds]
f1refly has quit [*.net *.split]
baweaver has quit [*.net *.split]
Welog has quit [*.net *.split]
olbat has quit [*.net *.split]
davic has quit [*.net *.split]
baweaver has joined #crystal-lang
f1refly has joined #crystal-lang
davic has joined #crystal-lang
Welog has joined #crystal-lang
olbat has joined #crystal-lang
HumanG33k has quit [Ping timeout: 265 seconds]
zorp has joined #crystal-lang
<oprypin> what was the shorthand for a question-mark property
<FromGitter> <Blacksmoke16> `getter?`?
<FromGitter> <Blacksmoke16> or `property?`
<oprypin> i want `foo.bar? ||= x` to do `foo.bar? || (foo.bar = x)`
<oprypin> do we have that yet?