<FromGitter>
<hmans> @paulcsmith Is that assuming you're terminating SSL yourself (in Crystal/Lucky)?
<FromGitter>
<paulcsmith> I'm not quite sure yet (still exploring), but I want it to check if the protocol is https and if it is not, do a permanent redirect to the request host/resource
<FromGitter>
<paulcsmith> I'm thinking for now I just check for an `X-Forwarded-Proto` header manually since there doesn't seem to be an `ssl?` or `protocol` method
<FromGitter>
<Blacksmoke16> can i have some help with JSON::PullParser?
<FromGitter>
<Blacksmoke16> the converter should parse the object and set the scope property to `"esi-wallet.read_character_wallet.v1"`
<FromGitter>
<Blacksmoke16> but idk what im doing :(
<FromGitter>
<Blacksmoke16> oh wait would help if my JSON is valid
<literal>
does Crystal have anything like File.which() from the Ruby ptools gem?
<FromGitter>
<Qwerp-Derp> I'm basically doing something like React, where I'm replacing a block of code that's not Crystal with Crystal, and then I want to format that
<FromGitter>
<Qwerp-Derp> Since the output from my parser isn't indented and stuff
<FromGitter>
<bew> You can simply import the Crystal parser, call parse on the code, then to_s on the result, et voilà
That_Guy_Anon1 has joined #crystal-lang
<FromGitter>
<Qwerp-Derp> How do I import the Crystal parser?
<FromGitter>
<Qwerp-Derp> Do I literally have to go to where Crystal is installed and require a huge path from there?
<FromGitter>
<Qwerp-Derp> I want to process everything within the `crx do` block as another language entirely, parse it, and turn it into native crystal code
<FromGitter>
<bew> that's pretty hard to do, which language?
<FromGitter>
<Qwerp-Derp> It's a custom markup language that I made
<FromGitter>
<Qwerp-Derp> Should I just use heredocs or something
<FromGitter>
<bew> that would be much easier
<FromGitter>
<codenoid> i move to mongo
<FromGitter>
<codenoid> i love mongo
<FromGitter>
<codenoid> btw, i have "212.442", what a regexp to find first "212." in string
<FromGitter>
<bew> @codenoid you should learn about how regex works, and how to make one, this one is quite easy to start
<FromGitter>
<codenoid> yeah @bew , actually 212. and 442 is dynamic value, i think i can use only /212./
<FromGitter>
<Blacksmoke16> is a helpful website to help learn as well
<FromGitter>
<bew> `/(\d+)\./` (note: @Blacksmoke16 without `\`, `.` means any char, so `123a` is valid with your regex)
<FromGitter>
<Blacksmoke16> yea i updated it
<FromGitter>
<bew> 👍
greengriminal has joined #crystal-lang
<FromGitter>
<bew> a regex always look odd ^^
<FromGitter>
<Blacksmoke16> its amazing how powerful it can be, yet so simple if you think about it
DTZUZO has joined #crystal-lang
greengriminal has quit [Quit: Leaving]
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 245 seconds]
pwned has joined #crystal-lang
<FromGitter>
<vusaalab> Hi guys do you have any idea why this happened ⏎ in src/ffmpeg/movie.cr:41: undefined method 'select' for JSON::Any ⏎ ⏎ ``` @metadata["streams"].select { |stream| stream["codec_type"] === "audio" }``` [https://gitter.im/crystal-lang/crystal?at=5b2dda266ceffe4eba2a4528]
<FromGitter>
<Qwerp-Derp> What is `@metadata["streams"]` meant to be
<FromGitter>
<vusaalab> it is json array ( JSON::Any )
<FromGitter>
<Qwerp-Derp> You have to put `.to_a` after `@metadata["streams"]`
<FromGitter>
<Qwerp-Derp> to cast the value into an array
<FromGitter>
<vusaalab> I did it ⏎ undefined method 'to_a' for JSON::Any (did you mean 'to_s'?)
<FromGitter>
<Qwerp-Derp> `.as_a` sorry
<FromGitter>
<vusaalab> Thank you it is working
<FromGitter>
<fgimian> yep, you'll need to cast it specifically
<FromGitter>
<hmans> @paulcsmith Sorry, I had to catch some sleep... it was around 2am here when we talked
<FromGitter>
<hmans> @paulcsmith If you have an external web server process (eg. nginx) terminate your SSL for you, it'll usually set a header like that for you to look for, yes.
<FromGitter>
<hmans> @paulcsmith If you intend to terminate the SSL yourself (and I have no idea if this is a good idea to begin with, but I'm not an expert on these matters), I would *guess* you could set up two separate HTTP::Server instances, one for plain HTTP, one for HTTPS, and have the latter provide some piece of information through its env/context.
<FromGitter>
<hmans> @paulcsmith If there is a more straight-forward way of doing it, I'm not seeing it
<FromGitter>
<hmans> `to_json` will return a String.
<FromGitter>
<hmans> You can't add things to a String like you would add them to a hash.
<FromGitter>
<hmans> Add `err_content["details"]` first, before calling `to_json` on it.
<FromGitter>
<rishavs> shucks. that was a stupid error. I guess i need to rest soon. Thanks!
<crystal-gh>
[crystal] fgimian opened pull request #6248: Corrected missing return value in the FileInfo flags method (master...bug/missing-return-for-flags) https://git.io/f4yNw
That_Guy_Anon has joined #crystal-lang
<FromGitter>
<Qwerp-Derp> Is it possible to somehow leverage the Crystal compiler to make custom `do` blocks with new syntax? I want to basically do something like react.js, and inject HDML (my markup language)'s code into that custom `do` block
<FromGitter>
<Qwerp-Derp> Nevermind I'll just do something like duktape
<FromGitter>
<hmans> Do you have an example of what you're aiming at?
<FromGitter>
<Qwerp-Derp> Pretty much everything within `crx do` and `end` is the custom markup language
<FromGitter>
<Qwerp-Derp> And this is in a custom file extension `.crx`, which gets parsed into `.cr`
<FromGitter>
<Qwerp-Derp> Pretty much what `react.js` does except for Crystal
<FromGitter>
<hmans> When you're referring to `react.js`, I'm assuming you mean JSX?
<FromGitter>
<Qwerp-Derp> Yeah
<FromGitter>
<hmans> Well, considering your crx syntax is not related to valid Crystal syntax, you could just plug it into a HEREDOC and pass that to your parser (which could be a macro so it happens at compile time.)
<FromGitter>
<S-YOU> or with do ... end instead of NamedTuple
<FromGitter>
<hmans> If you're willing to make it valid Crystal syntax, consider that there's a category of packages in the React world like hyperscript (and its many friends) that basically provide a JS DSL for generating HTML (in place of JSX)
<FromGitter>
<hmans> I remember seeing a package like that for Crystal, so at least one other person is going in this direction at the moment.
<FromGitter>
<hmans> Consider that HTML (or XML) tags are really just things with 0-n attributes and optional content, so it should map nicely to just plain Crystal methods.
That_Guy_Anon has quit [Ping timeout: 276 seconds]
That_Guy_Anon1 has quit [Client Quit]
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 240 seconds]
<FromGitter>
<fgimian> Hey guys, can you think of a shorter or cleaner way to get the MD5 checksum of a file than this? https://play.crystal-lang.org/#/r/4d36
<FromGitter>
<fgimian> true, I've not really understood what `update` is doing yet, but if I can incorporate the buffering then this may be the best approach
<FromGitter>
<fgimian> the `.update` method is the one taking all the time in the md5 lib
<FromGitter>
<S-YOU> Yeah, you can append multiple payload with update
<FromGitter>
<fgimian> oh cool
<FromGitter>
<fgimian> true
<FromGitter>
<fgimian> I'm just sad that Python beat it
<FromGitter>
<S-YOU> C beat it, not python
<FromGitter>
<fgimian> true, I'm certain Python is using a C implementation under the hood
<FromGitter>
<fgimian> oh, it seems they use OpenSSL under the hood
<FromGitter>
<fgimian> thanks, i'll try that
<FromGitter>
<S-YOU> I double that StaticArray has little overhead, if you pass it around.
<FromGitter>
<fgimian> yeah
<FromGitter>
<fgimian> do you think it's worth raising a case on the poor performance of the native implementation?
<FromGitter>
<S-YOU> Well, it will basically be low priority, in my opinion.
<FromGitter>
<S-YOU> There is room to improve C binding I think.
<FromGitter>
<fgimian> yeah that's what I think too
<FromGitter>
<S-YOU> I mean, the way you call or init, update stuff.
<FromGitter>
<fgimian> exactly yeah
<FromGitter>
<fgimian> it would be nice to see a similar interface to Digest for OpenSSL
<FromGitter>
<S-YOU> I guess, performance issue on processing file, not checksum but I will try to measure.
<FromGitter>
<S-YOU> how about file size? 50M?
<FromGitter>
<fgimian> yep 43 MB in my case
<FromGitter>
<fgimian> i found this in the unit tests
<FromGitter>
<S-YOU> May be I will make LibMd5sum, lol
<FromGitter>
<fgimian> So perhaps there is a nice way do build it up
<FromGitter>
<S-YOU> Not using openssl, it means it can do extreme optimization for only purpose.
<FromGitter>
<fgimian> aah I see
<FromGitter>
<S-YOU> as I thought, It does not load whole file, it read chunk by chunks and processing md5 during that. It mean there can be only one small allocation, and reuse it.
<FromGitter>
<fgimian> yeah
<FromGitter>
<fgimian> I found a few useful things in the unit tests for OpenSSl
<FromGitter>
<fgimian> I think this will work! 😄
<FromGitter>
<S-YOU> Cool
<FromGitter>
<fgimian> I'll let you know how I go soon
<FromGitter>
<fgimian> 🍺
<FromGitter>
<S-YOU> You're welcome 🍻
<FromGitter>
<fgimian> sadly the same result my friend
dxt has joined #crystal-lang
<FromGitter>
<fgimian> this took `0.462s`
<FromGitter>
<fgimian> if i remove the `io.read` line I think all the time will be reduced
<FromGitter>
<fgimian> np buddy
<FromGitter>
<S-YOU> sorry again, try File.read only
<FromGitter>
<S-YOU> I doubt that it is file read it is slow.
<FromGitter>
<fgimian> yeah it's not File.read, but I'll double check
<FromGitter>
<fgimian> just for the reading of the file in 1024 byte blocks, I get `0.024s`
<FromGitter>
<S-YOU> One block is normally larger than 4k in disk (depends on filesystem)
<FromGitter>
<fgimian> true
<FromGitter>
<fgimian> 16384 bytes => `019s`
<FromGitter>
<S-YOU> you can read like 256k (optimal is depends on OS, File System or Disk type)
<FromGitter>
<fgimian> ok let me try
<FromGitter>
<fgimian> i'll try going higher
<FromGitter>
<fgimian> probably about 0.17s is the best I can do
<FromGitter>
<fgimian> is that bad for a 43 MB file?
<FromGitter>
<fgimian> i need to try in Python too
<FromGitter>
<S-YOU> I see. let me try without overhead here
<FromGitter>
<fgimian> yeah Python is slower for the reading
<FromGitter>
<fgimian> ``````
<FromGitter>
<fgimian> so I think my problem REALLY is the MD5 algorithm
<FromGitter>
<S-YOU> okay
<FromGitter>
<S-YOU> well, right
<FromGitter>
<fgimian> 😢
<FromGitter>
<S-YOU> fileread only without overhead on my machine ⏎ time ./md5sum ~/Downloads/pianoteq_trial_v621.dmg ⏎ 44693913 ⏎ ./md5sum ~/Downloads/pianoteq_trial_v621.dmg 0.00s user 0.04s system 89% cpu 0.043 total [https://gitter.im/crystal-lang/crystal?at=5b2e5902ad21887018d80f56]
<FromGitter>
<fgimian> oh yea
<FromGitter>
<S-YOU> yeah, i will try md5 very soon now
<FromGitter>
<codenoid> yeah, something you need to find your-self algorithm for your self-problem
<FromGitter>
<vlazar> yes, not sure what to do with this, probably Kemal needs update
<FromGitter>
<S-YOU> you should ask on stackoverflow or serverfault. that is general OS question.
moei has joined #crystal-lang
dxt has quit [Ping timeout: 240 seconds]
dxt has joined #crystal-lang
<FromGitter>
<crash2burn_twitter> anyone know of a way to get the class name of an object without the module prefixed (besides doing obj.class.to_s and doing a string operation to remove the prefix)?
<FromGitter>
<vladfaust> I'd like `do` syntax to work as well
wontruefree has joined #crystal-lang
<FromGitter>
<predatorian3> Extremely noob question, but when using HTTP::Server#bind, I keep getting a `no overload matches 'HTTP::Server#bind' with type Int32` even though I copied it directly from the documentation thinking I typed it wrong.
<FromGitter>
<predatorian3> What am i being told then to do? using `server.bind 5000` didn't work, `server.bind "0.0.0.0", 5000` didn't either
<FromGitter>
<bew> I think the error for unterminated
<FromGitter>
<bew> About unterminated parenthesized expression is a bug, you might want to open an issue
<FromGitter>
<bew> As a workaround you could capture the block of field, and use it
Jenz has joined #crystal-lang
<Jenz>
How would I parse `{ "list":[1,2,3] }` into a crystal object
<Jenz>
?
<Jenz>
`NameTuple(list: Array(Int32))`?
<RX14>
that would work
<RX14>
you could also just use JSON.mapping
<Jenz>
Really? Ok thanks
<RX14>
yeah
<RX14>
create an object with a single list property
<RX14>
thats an Array(Int32)
<RX14>
doing that vs using a named tuple would depend on the situation
wontruefree has quit [Quit: bye]
<FromGitter>
<n00ax> @j8r Yeah, I saw the former, my only problem with qemu-user-static is that it runs with traditional emulation during the compile phase, which in my experience can be quite slow (albeit provides a more reliable environment, but perhaps I am wrong?)....
<FromGitter>
<vlazar> new to docker, used multistage builds to compile static binary in alpine
<FromGitter>
<vlazar> works well but there are intermediate docker images left
<FromGitter>
<vlazar> is there a better way?
<FromGitter>
<vlazar> maybe using separate docker container with alpine + crystal to build binary and then just copy it to clean alpine?
<RX14>
nah just clean up the intermediates
<RX14>
the intermediates are only there for the build cache next time
<RX14>
as in, they're there because they're useful
<RX14>
you can delete them with an argument to docker build
<RX14>
if you're not going to use the cache anyway
<RX14>
docker build --force-rm I think
<FromGitter>
<vlazar> use case: constantly changing source and building docker images to run app and test, wouldn't this flow kill my SSD? :)
<FromGitter>
<vlazar> intermediate images are always changing too and they are quite large compared to final alpine image with single binary which is like 20Mb
<RX14>
yeah
<FromGitter>
<vlazar> intermediate are > 400Mb
<crystal-gh>
[crystal] jcs opened pull request #6250: Thread.allocate_stack: Pass MAP_STACK to mmap() on OpenBSD (master...master) https://git.io/f4SGf
<FromGitter>
<vlazar> I guess I'l just use hard drive than :)
<RX14>
you just have to manually delete the intermediates
<FromGitter>
<vlazar> thank you! yes, that's what I'm doing now, but this is expensive so I was wondering if there is a cleaner way
zachk has joined #crystal-lang
zachk has quit [Changing host]
zachk has joined #crystal-lang
rocx has quit [Quit: laptop's latch clicking, barstool screeching as he leaves, he hates these mornings. -- a haiku]
Jenz has quit [Quit: leaving]
snsei has joined #crystal-lang
faustinoaq has joined #crystal-lang
snsei has quit [Ping timeout: 276 seconds]
<crystal-gh>
[crystal] asterite opened pull request #6251: Add JSON::Any#dup and YAML::Any#dup (master...feature/6220-json-any-dup) https://git.io/f4SnL
<FromGitter>
<asterite> Did someone every write a tool to check that code snippets in doc comments compile and run well? I remember someone did it but can't find it... I think it's a nice thing to have, probably fun to implement, so I might give it a try and have it built-in in the language
<FromGitter>
<hmans> sup @asterite! I remember having a discussion about doctests here a few weeks ago and not everybody was agreeing they were a good idea.
<FromGitter>
<hmans> (I like them.)
<FromGitter>
<asterite> Well, given that there are some issues in the docs not being updated to API changes, I think it's a good idea to automate them to prevent them getting out of sync
<FromGitter>
<asterite> At least check that they compile...
<FromGitter>
<hmans> It'd be great. I'm too useless to help out. Could this work through annotations (ie. the parser converting code blocks within code comments into annotations to be sourced from a doctest statement in a spec?)
That_Guy_Anon has quit [Quit: Leaving]
<FromGitter>
<asterite> Maybe. But it's simpler to just scan the code like the doc generator does. So something separate of spec
<FromGitter>
<asterite> I
<FromGitter>
<asterite> But I found an issue about it and it seems compiling all samples was too slow, so maybe it won't be possible after all
rocx has joined #crystal-lang
<FromGitter>
<hmans> Can Macros emit comments to be picked up by the doc generator? (I'm guessing no?)
<FromGitter>
<bew> Yes they can
<FromGitter>
<j8r> If we look more closely, code snippets and specs overlap quite a bit. If we can generate code snippets from the specs - it may be possible - this will solve the issue, and add a lot more example in the generated API doc (they can be collapsed in the UI)
<FromGitter>
<asterite> They way Go does it is good. You can specify some files as examples
<FromGitter>
<j8r> This may include specs for us?
<FromGitter>
<asterite> What do you mean?
<FromGitter>
<hmans> @bew If Macros can emit code comments (that will be picked up by the doc generator), code examples that should be tested could be defined through such macros?
<oprypin>
asterite, there was such a tool and i cant find it either
<FromGitter>
<j8r> What I mean is the actual code snippets as comments are example. The specs can also be used as examples. So why not use specs?
<oprypin>
for some reason i think it was made by a japanese person
<oprypin>
j8r, these concepts cover different avenues and merging them gives you something that doesn't quite fulfill either of the purposes
<oprypin>
obviously you dont want assertions in examples and you don't want to limit specs so they also happen to be a nice example
<FromGitter>
<asterite> Specs are not examples
<FromGitter>
<j8r> I don't really get why we can't use them as example... Sure the comments explaining what the method do should be kept, but on the pure code side, most use case should be covered by the related specs of the method?
<FromGitter>
<j8r> Sorry I may be wrong, I will see better If you give me an example to prove me wrong 😄
<FromGitter>
<hmans> I'm off to bed. Good night everyone.
<FromGitter>
<codenoid> spec is like example
<FromGitter>
<j8r> Yes! To sum up, today we have comments that explains what objects, methods etc are. This is nice, and for sure won't be touched. ⏎ On another side, there are have also code snippets to add examples to them. ⏎ They tell us how to use, and what they return with e.g `[1, 2] + [2, 3] # => [1,2,2,3]` ⏎ This is exactly what specs do with e.g `([1, 2] + [2, 3]).should eq [1,2,2,3]` ⏎ Furthermore, by their nature,
<FromGitter>
<Daniel-Worrall> They can be used as examples for users to understand how the classes are supposed to work, but they shouldn't be seen as the same as documentation examples for the API. They are a separate entity and since there have been instances of them not being updated in PRs, a tool to check that the examples compile is at least something we can do to combat that problem
<FromGitter>
<Daniel-Worrall> In my opinion, it can be prevented user side if we had a Find Usages tool (like in an ide) so we could make sure the examples in those calls aren't affected by these changes
<FromGitter>
<Daniel-Worrall> Another thought is to have all examples have a 1:1 spec and have them described as such in the spec itself so that if it fails in the spec, it can be looked at in the examples.
<FromGitter>
<j8r> Testing the examples must be done in one way or another, and for now all solutions are heavy. Personally if we ditch all the examples and instead a have nice browsable HTML UI for specs, I will be happy. Of course I'm probably alone to think that 😃