<FromGitter>
<fgimian> @faustinoaq Same here, I don't miss much about Python having used Crystal for a few days. I've coded a bit in Ruby in the past too and always enjoyed it. I would honestly say that Ruby / Crystal are more "beautiful". The import system in Ruby/Crystal is more like C/C++ though, while Python has a very strict way to ensure no namespace collisions.
<FromGitter>
<fgimian> Python is an awesome language though, and I havev been coding in it since 2011 and always enjoyed it too 😄
rohitpaulk has quit [Ping timeout: 260 seconds]
<FromGitter>
<S-YOU> For wchat_t, I think you need to define it inside {% if flag?(x86_64) %} or even by OS flags
<FromGitter>
<fgimian> @S-YOU thanks, I'll see if I can find an example of that in the Crystal source now 😄
<FromGitter>
<S-YOU> @evandrojr, I am not sure you could use LLVM 7 to compile crystal, working LLVM is 5 as far as I noticed.
sz0 has quit [Quit: Connection closed for inactivity]
<FromGitter>
<fgimian> @S-YOU Sorry, but just one more question if I may; any idea how I can do this in Crystal ⏎ ⏎ ```typedef int (CALLBACK *UNRARCALLBACK)(UINT msg,LPARAM UserData,LPARAM P1,LPARAM P2);`````` [https://gitter.im/crystal-lang/crystal?at=5b0a2025edd06f7d15e7ec1f]
<FromGitter>
<fgimian> 😕
<FromGitter>
<evandrojr> thank @S-YOU here @RX14 said to use the newest but I guess 7 is too new!
<FromGitter>
<bew> Note that you'll end up with a string of size 1024
<FromGitter>
<bew> but the actual content is probably less than that
<FromGitter>
<fgimian> I see, is that'll do for now, but is there any way to strip off the \0s?
<FromGitter>
<fgimian> yeh it is
<FromGitter>
<bew> you could send a pointer, like `String.new(the_array.to_unsafe)` and the String constructor will do a `LibC.strlen` to find out the size of the string (finding the first \0)
<FromGitter>
<bew> or if you have another way to get the size, you can pass it as 2nd param
sz0 has joined #crystal-lang
<FromGitter>
<fgimian> thanks so much @bew
<FromGitter>
<fgimian> sorry for the late reply, was just grabbing lunch
<FromGitter>
<michaelteter_twitter> Super-beginner question... I see how to init (create) an app, and I know how to run a single file.cr, but what is the standard way of running a project? In some other languages, the build tool will have a concept of "build and run the project from this top level project directory"
<FromGitter>
<fgimian> @michaelteter_twitter are you perhaps just looking for the `crystal build` command that will build a binary for you?
<FromGitter>
<fgimian> 😄
<FromGitter>
<michaelteter_twitter> Yes, but without args I just get a usage output
<FromGitter>
<michaelteter_twitter> for example, in Clojure with Leiningen, in the top level directory of my project i would just "lein run"
<FromGitter>
<michaelteter_twitter> So if my project is dbtest, and I am in dbtest/, I need to type crystal ./src/program.cr
<FromGitter>
<fgimian> that's my understanding thus far with Crystal, you must reference the top-level `*.cr` file as far as I know
<FromGitter>
<fgimian> *Disclaimer*: I only started coding in Crystal on Friday
<FromGitter>
<fgimian> 😆
<FromGitter>
<michaelteter_twitter> ahh ok
<FromGitter>
<fgimian> perhaps someone more experienced can confirm this 😄
<FromGitter>
<michaelteter_twitter> well I guess crystal build src/prog.cr is fine. it generates an executable "prog" in the top directory
<FromGitter>
<fgimian> yep
<FromGitter>
<fgimian> 😄
<FromGitter>
<michaelteter_twitter> Thanks
<FromGitter>
<fgimian> np mate, glad I could help
<FromGitter>
<michaelteter_twitter> I didn't get very far before I got stuck again! Trying to make a connection to postgres, but I can't figure out what name to require to use the crystal-pg shard
<FromGitter>
<michaelteter_twitter> I've tried "pg", "crystal-pg", "postgres", etc. The Crystal docs show "mysql", which I'm sure works for mysql. But sadly the crystal-pg readme doesn't have an example.
<FromGitter>
<bew> It should be pg
<FromGitter>
<bew> Did you installed the shard?
<FromGitter>
<michaelteter_twitter> Thanks. I guess it's late and I'm tired. I tried "PG" but not "pg". Now it builds.
dragonkh has quit [Ping timeout: 248 seconds]
<FromGitter>
<michaelteter_twitter> now to find a connection string example that includes username and password...
<FromGitter>
<michaelteter_twitter> (for pg)
<FromGitter>
<bew> Probably the same as everything: `user:passwd@host:port` or sth like that
<FromGitter>
<bew> Probably with `postgres://` in front of that
<FromGitter>
<michaelteter_twitter> Perhaps
<FromGitter>
<michaelteter_twitter> That was it, thank you
dragonkh has joined #crystal-lang
dragonkh has quit [Read error: Connection reset by peer]
<FromGitter>
<hmans> @michaelteter_twitter - you would be looking for `shards run`, which sadly does not exist at this moment -- I remember seeing a discussion on GitHub where people weren't exactly agreeing on how much tooling shards should provide that you could otherwise get from established tools like `make`.
<FromGitter>
<hmans> I did stumble over this too, when I was starting out. `shards` certainly set the expectation that it would also be able to run a project
<FromGitter>
<michaelteter_twitter> I know this is a young language and tooling, so I can live with it :) I was just a bit lost... And from the examples I've seen, I haven't noticed a start to finish demonstration of some of these things.
rohitpaulk has joined #crystal-lang
<FromGitter>
<fgimian> I've got another little / weird question. It seems that the RAR C library uses a widechar for its unicode strings. i.e. a static array of UInt32T. Now I "believe" this means that it's UTF-32 encoded. My archive name is `capsule_container.rar` and I can see the following being return from the library: ⏎ ⏎ ```arc_name_w: StaticArray[99_u32, 97_u32, 112_u32, 115_u32, 117_u32, 108_u32, 101_u32, 95_u32,
<FromGitter>
<fgimian> Can you suggest a way that I can convert this to and from a regular UTF-8 String as used by Crystal?
rohitpaulk has quit [Ping timeout: 264 seconds]
<FromGitter>
<fgimian> i think that perhaps I'm misunderstanding, I'm certain they use a UInt32 for each character, but indeed that could be storing each character in UTF-8 encoding ... this stuff always confuses me 😆
<FromGitter>
<fgimian> ok so yeah, unicode characters can be up to 4 bytes, and this is the length of a UInt32, so I guess it IS UTF-8
<FromGitter>
<fgimian> but I'm just not sure how to "convert it" to a String 😄
<FromGitter>
<fgimian> ```header_data.arc_name_w[0].chr``` gives me the character
<FromGitter>
<hmans> https://play.crystal-lang.org/#/r/45hg - This still confuses me. Why would the compiler complain about `greet(name : Nil)` not being implemented, considering the path through the code is pretty static?
<FromGitter>
<hmans> I would have expected the `if ` in line 23 to mark `user.name` as non-nil within this branch
<FromGitter>
<hmans> Oh!
<FromGitter>
<hmans> I remember that detail from the book about assigning something to a local variable first.
<FromGitter>
<hmans> Thanks for being my rubberdruck, everyone \o/
<FromGitter>
<bew> what if the second time `user.name` returns nil? the compiler can't assert that it won't change
<FromGitter>
<hmans> @bew That makes complete sense. Thanks.
<FromGitter>
<hmans> It'd be great to be able to write one-liners like `greet name if name = user.name`
<FromGitter>
<hmans> Best alternative I can come up with for now: `(name = user.name) && greet name`
<FromGitter>
<bew> great I don't know, I prefere the multi-line form, to better see the condition and the new variable
<FromGitter>
<hmans> Yeah, I'm not being entirely serious about using the form I just posted, it does obfuscate intent more than I like.
<FromGitter>
<hmans> (I'm building an ATOM feed builder, and I'm doing these sanity checks within its implementation to keep the usage as straight-forward as possible)
<FromGitter>
<fgimian> This is the best I could come up with 😄
<FromGitter>
<fgimian> I added a Chinese character in there to test unicode properly
<FromGitter>
<S-YOU> Actually Decoder class(private) in IO (io/encoding.cr) should do that properly with Iconv, but I couldn't come up with working solution.
<FromGitter>
<bararchy> @godmode97 you are missing dev libs, if you're on Ubuntu please run `apt-get install libxml2-dev`
<FromGitter>
<godmode97> im using ubuntu on windows, thank you @bararchy , kemal is running now :)
rohitpaulk has joined #crystal-lang
<FromGitter>
<bararchy> 👍
rohitpaulk has quit [Ping timeout: 260 seconds]
<FromGitter>
<hmans> @godmode97 How is the Linux subsystem in Windows working out for you? After more than a decade of developing on a Mac, I'm tempted to give that a try...
<FromGitter>
<drum445> Nah it does work, my code was just wrong lol ;)
<FromGitter>
<drum445> fixed now, cheers
<FromGitter>
<drum445> Do you know the JSON.mapping. Is there a way to have the object param be "time_left" but the json name be "timeLeft" ⏎ I don't like having to use camel case param names in ruby
Nik736 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
alex`` has quit [Ping timeout: 260 seconds]
return0e has quit [Remote host closed the connection]
alex`` has joined #crystal-lang
<FromGitter>
<michaelteter_twitter> Has anyone used stumpy_core shard? I tried to add it to my shards file, but I get `Error resolving stumpy_core (*, ~> 1.8, ~> 1.7.0)`
<FromGitter>
<michaelteter_twitter> unfortunately the github readme for the stumpy projects don't show examples of how it should be stated in the shards.yml file, so maybe I've described things wrong...
<FromGitter>
<michaelteter_twitter> I didn't specify a version, so shouldn't it just grab the most current?
<RX14>
yes it should
<RX14>
stumpy_png depends on stumpy_core
<FromGitter>
<michaelteter_twitter> I removed the version from png as well. same problem
<FromGitter>
<michaelteter_twitter> are the dependencies not fetched in order?
<RX14>
nope
<RX14>
i see the problem
<RX14>
the latest tagged version of stumpy_core specifies ~> 1.8
<RX14>
oops
<RX14>
the latest tagged version of stumpy_png specifies ~> 1.8
<RX14>
the latest tagged version of stumpy_utils specifies ~> 1.7
<RX14>
and those are incompatible
<RX14>
stumpy_utils is the one specifying ~> 1.7.0
<FromGitter>
<michaelteter_twitter> hmm
<RX14>
so it needs to be forced `branch: master`
Nathanaelle has quit [Ping timeout: 260 seconds]
<FromGitter>
<michaelteter_twitter> Is stumpy the only (or best) library for drawing? I just need some primative drawing tools and the ability to generate svg or png
<RX14>
i think it's really the only one
<FromGitter>
<michaelteter_twitter> Sorry, which needs to be branch: master? This is my 3rd hour of exposure to Crystal, so I'm not clear on much of this initial stuff
<RX14>
the problem is that stumpy_png depends on stumpy_core 1.8.x and stumpy_utils depends on stumpy_core 1.7.x
<RX14>
stumpy_utils has a commit in master to fix this
<RX14>
but it's not in a release yet
<RX14>
so you should force branch: master on stumpy_utils
<FromGitter>
<michaelteter_twitter> Understood. So I put "branch: master" under the stumpy_utils dep
<RX14>
yes
<FromGitter>
<michaelteter_twitter> thanks
<RX14>
and you can remove the stumpy_core one :)
<RX14>
if you want
Nathanaelle has joined #crystal-lang
<FromGitter>
<michaelteter_twitter> excellent, thank you very much!
<RX14>
no problem
<RX14>
the error message should be improved tbh
<RX14>
say which dependencies have which version specifiers
<RX14>
then you'd know that stumpy_png depends on stumpy_core 1.8.x and stumpy_utils depends on stumpy_core 1.7.x
<RX14>
and that's a pretty good place to start debugging
<RX14>
i hate that gitter appends _twitter to some people's usernames
return0e has joined #crystal-lang
<FromGitter>
<michaelteter_twitter> yup, sorry. I didn't even want to use twitter, but I didn't like the other two oauth login options
<Vexatos>
I mean you could change the bot to remove any _twitter
<RX14>
thats not a bijective mapping Vexatos
<Vexatos>
The chance of that actually being part of a username is rather low I feel
<Vexatos>
well true I guess
<RX14>
and the chances of it being abused are high?
<Vexatos>
RX14, I mean I could change the hexchat script to not show it, but autocomplete to still use it
<Vexatos>
The version you have is specific to you anyway soo
<oprypin>
Vexatos, problem is to ping that person you need the suffix
<Vexatos>
yea which is why I suggested the latter to RX14
<RX14>
yes but what if you have both
<Vexatos>
Hm
<Vexatos>
well they would show up as the same person
<RX14>
what if someone signs up to gitter with asterite_twitter
<oprypin>
there is, like, one user of the hexchat script, so whatever
<Vexatos>
tab complete would obviously still distinguish them
<RX14>
and then I dont notice
Nathanaelle has quit [Ping timeout: 260 seconds]
<RX14>
it's added complexity for a really tiny bother
<Vexatos>
does the gitter twitter login use the twitter account name?
<oprypin>
yes
p0p0pr37_ has joined #crystal-lang
p0p0pr37_ has joined #crystal-lang
<Vexatos>
then it's not an issue
<oprypin>
(then there's _gitlab btw)
<Vexatos>
good to know.
<Vexatos>
I mean if it doesn't bother you that much I don't need to bother either
<Vexatos>
Was just a suggestion :P
Nathanaelle has joined #crystal-lang
<oprypin>
the hope is that it bothers the actual person enough to give up the twitter login :|
p0p0pr37 has quit [Ping timeout: 248 seconds]
p0p0pr37_ is now known as p0p0pr37
Nathanaelle has quit [Ping timeout: 252 seconds]
Nathanaelle has joined #crystal-lang
<FromGitter>
<drum445> General question, if I have a method that carries out a process and will return the issue (if there is one) but this issue can vary, how would I best go about doing this ⏎ something like: https://play.crystal-lang.org/#/r/45n6
<FromGitter>
<drum445> It's a JSON api so if the db call can't find x I want to say that, same as if it can't find y
rohitpaulk has quit [Remote host closed the connection]
Nathanaelle has quit [Ping timeout: 260 seconds]
Nathanaelle has joined #crystal-lang
Nik736 has joined #crystal-lang
Nathanaelle has quit [Read error: Connection reset by peer]
<FromGitter>
<godmode97> @hmans windows has its own subsystem of ubuntu, it's also the same as running it with the usual ubuntu. though the files are stored inside the `APPDATA` which makes it quite difficult for me to locate.
Nathanaelle has joined #crystal-lang
Nathanaelle has quit [Read error: Connection reset by peer]
<FromGitter>
<fridgerator> which includes libyaml-dev, it looks like it cannot find the libyaml library
<FromGitter>
<godmode97> @fridgerator thanks! it's now working!
<FromGitter>
<fridgerator> 👍
Jenz has quit [Quit: leaving]
Nik736 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
p0p0pr37_ has joined #crystal-lang
p0p0pr37 has quit [Read error: No route to host]
p0p0pr37_ is now known as p0p0pr37
Nathanaelle has quit [Ping timeout: 256 seconds]
<FromGitter>
<vladfaust> I got 1ms response on a real-world application with JWT authentication, PostgreSQL querying and JSON response building; only 135μs goes to Crystal itself, other to Postgres. Is that a break-through?
sherjilozair has joined #crystal-lang
<FromGitter>
<drum445> I have similar results, but using Maria and cookie based sessions
<FromGitter>
<drum445> although I imagine that must be running locally and not on https
<FromGitter>
<vladfaust> I measure it by handlers, not from outer tools, therefore "locally" and "https" do not make sense, I suppose
<FromGitter>
<drum445> ah makes more sense, still super nice
<FromGitter>
<drum445> Crystal and Go are just the kings of performance
<FromGitter>
<drum445> Especially with how cheap fibers are to create
<FromGitter>
<vladfaust> So, this performance is comparable with Go?
<FromGitter>
<vladfaust> I got 100k on 4 cpus with empty server
<FromGitter>
<drum445> There is a lot of variables, such as frameworks to consider
<FromGitter>
<drum445> but Go and Crystal seem to be on the upper end of performance
<FromGitter>
<Blacksmoke16> is there reasoning behind why you can type restrict params on macros?
<FromGitter>
<bew> you can't
<FromGitter>
<bew> as to why, I don't know, I'd like to too sometimes
<FromGitter>
<vladfaust> I'm benching with wrk and get 400ms responses from PostgreSQL when using multiple wrk threads
<FromGitter>
<Blacksmoke16> oh well
<FromGitter>
<drum445> more general question, but why do you choose Postgres over Maria/MySQL ?
<FromGitter>
<vladfaust> I got used to it. Doing PostgreSQL for like 4 years
sherjilozair has quit [Quit: Leaving...]
<FromGitter>
<drum445> Fair enough, I've been interested in using it but don't see any reason to use it over the others tbh
<FromGitter>
<drum445> I guess it's just stick to what you know
<FromGitter>
<bew> (note @vladfaust : you can do `Core.prepare_params {{ *params }}` too ;)
<FromGitter>
<vladfaust> @bew noted, would experiment with
<FromGitter>
<vladfaust> Despite of a single response being stretched to 250-400ms, wrk gives 1800 rps, which results in 0.55ms (!) response time
<FromGitter>
<vladfaust> BTW, scaling from 1 to 4 cores gives 2100 RPS, I think it's the DB's issue - it's running in a single Docker container on my local machine as well
<FromGitter>
<vladfaust> I wish tarantool 2.0 released, I've already written driver for it: https://github.com/vladfaust/tarantool-crystal. It gives 40k rps at dozen of simul connections; 25 microseconds vs PostgreSQL's milliseconds
<FromGitter>
<vladfaust> Anyone knows a cloud provider for PostgreSQL suitable for tons of simultaneous connections and maybe give me free credits for benchmarking realworld.io back-ends?
<FromGitter>
<vladfaust> BTW, I don't think I'm capable of benching all the back-ends by my own 😕
<FromGitter>
<girng> You could even say "inhumane syntax" since it's basically torture 😆
<FromGitter>
<faustinoaq> "inhuman syntax" XD
<FromGitter>
<faustinoaq> What about Rust? :;)
bmcginty has quit [Ping timeout: 256 seconds]
p0p0pr37_ has joined #crystal-lang
p0p0pr37_ has joined #crystal-lang
p0p0pr37 has quit [Read error: Connection reset by peer]
p0p0pr37_ is now known as p0p0pr37
<FromGitter>
<j8r> the worst are the Windows `bat` files - when I first see the syntax, I wanted to flew away back to `sh` 💀
<FromGitter>
<fridgerator> batch files are the worst
<FromGitter>
<fridgerator> I have to write them sometimes for jenkins builds
<FromGitter>
<fridgerator> I hate it
<FromGitter>
<galvertez> is there a better way to turn `Hash(K,V)` into `JSON::Any` than doing `JSON.parse(object.to_json)`? i can't figure out how to cast anything as `JSON::Any` and i'm completely out of ideas
<FromGitter>
<galvertez> JSON::Type wasn't much help either because as soon as i return anything more specific than JSON::Type it barks at me just the same
<FromGitter>
<fridgerator> are the keys known at compile time or not?
<FromGitter>
<girng> S T A T I C A L L Y - T Y P E D
<FromGitter>
<girng> @faustinoaq 😆
<FromGitter>
<j8r> @galvertez what do you want to do?
<FromGitter>
<galvertez> they're not known
<FromGitter>
<j8r> has you JSON a mapping?
<FromGitter>
<galvertez> i'm trying to build jsonrpc because the only jsonrpc shard i found... i wasn't crazy about the way it worked and the last commit is over a year old.
<FromGitter>
<galvertez> so when a request comes into the server it will be known what the parameters and return types are, but that is only when writing the methods. they're not knowable before the methods are known. i am trying to store the methods as `Proc(JSON::Any, JSON::Any)` so that based on the request's `method` key, it will know which block to use
<FromGitter>
<galvertez> however, the `parameters` key is not knowable at the time i create a storage for the blocks
<FromGitter>
<galvertez> rather, the value of that key is not knowable
<FromGitter>
<galvertez> and might not even exist for some requests
<FromGitter>
<j8r> I'm reading the specs
<FromGitter>
<j8r> I think you can use a mapping
<FromGitter>
<galvertez> so what i want is for the handler to parse the request, select the correct block based on `request.method` and then pass that block `request.params`. that part hasn't been difficult; since `JSON.mapping` can't decide what type the `params` key should hold, it will always be `JSON::Any`. no problem there. but during processing, (what the methods will return can't be known until after the handler is already
<FromGitter>
... instantiated)
<FromGitter>
<j8r> I agree for params yes, it can be Array or Hash or nil
<FromGitter>
<galvertez> right, params isn't the hard part
<FromGitter>
<galvertez> `result` from the response object is the hard part
<FromGitter>
<girng> imo, you should just do json.parse it makes your life 10x easier and unless you run into perf issues (which 90% won't happen) you should be fine
<FromGitter>
<j8r> why result is the hard part?
<FromGitter>
<galvertez> because i, while writing this shard
<FromGitter>
<galvertez> can't know what a user of the shard's return type will be when they write an rpc method
<FromGitter>
<j8r> Note that you may want to avoid using JSON.parse, because vs a mapping the performances are considerably worse
<FromGitter>
<galvertez> yeah, i'm using mapping right now for capturing requests and responses
<FromGitter>
<j8r> so the result can be either a string or an int?
<FromGitter>
<galvertez> but getting them packaged after processing is really confusing for me
<FromGitter>
<galvertez> the result can be any type
<FromGitter>
<galvertez> any valid json type
<FromGitter>
<galvertez> i can't know what the result will be ahead of time; that is up to the developer using the shard
<FromGitter>
<j8r> Crystal is statically typed, so at the end either you enforce a type for result, or do a tricky hack and have a hard-to-handle union type like `String | Int32 | Nil`
<FromGitter>
<galvertez> the type will be enforced
<FromGitter>
<galvertez> it will be knowable when the rpc is defined
<FromGitter>
<j8r> so... no problem?
<FromGitter>
<galvertez> the problem is that i can't write the shard to be used
<FromGitter>
<galvertez> without already knowing the type that the users will return
<FromGitter>
<j8r> What do you mean?
<FromGitter>
<j8r> I think I understand you
<FromGitter>
<j8r> You can use a macro
<FromGitter>
<galvertez> i can't store the `Proc(A,R)` without knowing what `R` is going to be. i want to use `JSON::Any` or `JSON::Type` but i can't cast the results as those
<FromGitter>
<galvertez> oh that's not the right snippet
<FromGitter>
<galvertez> hang on
<FromGitter>
<j8r> carc.in me a sample to fix ;-)
<FromGitter>
<bew> you could store a proc that returns a json, or that write the final result json to an io
<FromGitter>
<galvertez> yeah @bew that's exactly what i'm trying to do. but as soon as a proc returns anything other than JSON::Any or JSON::Type, i have problems. i tried writing a macro that would wrap the user's proc and cast the result as one of those but it said i can't
<FromGitter>
<bew> what do you want to return a JSON::Any ?
<FromGitter>
<bew> or JSON::Type
<FromGitter>
<bew> what will you do with it?
<FromGitter>
<bew> (first question was 'why' not 'what')
<FromGitter>
<j8r> furthermore the user expect a type, thus `Any` can be avoided
<FromGitter>
<j8r> @galvertez can you paste some code in https://carc.in/ ?
<FromGitter>
<galvertez> i'll have to re-type it
<FromGitter>
<galvertez> i have basically torn my program apart trying to get *anything* resembling my intent to work lol
<FromGitter>
<galvertez> @bew i don't care which it is. as long as it can turn into a JSON string and the client can parse it :)
<FromGitter>
<galvertez> the result object will only exist long enough to be serialized and shipped off to the client; no further processing will occur ever