ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.34.0 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
deavmi has quit [Ping timeout: 258 seconds]
deavmi has joined #crystal-lang
<FromGitter> <simonhf> came up with this little wrapper for caching one liners: ⏎ https://github.com/crystal-lang/crystal/issues/9364#issuecomment-635011824
ryanprior has quit [Ping timeout: 246 seconds]
hamoko[m] has quit [Ping timeout: 246 seconds]
ryanprior has joined #crystal-lang
lanodan has quit [Ping timeout: 260 seconds]
hamoko[m] has joined #crystal-lang
lanodan has joined #crystal-lang
zorp_ has joined #crystal-lang
<FromGitter> <636f7374> ⛵️ Available - Crystal HTTP2 Client and Server (https://github.com/636f7374/forest.cr)
<FromGitter> <636f7374> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ecf151fb101510b202054c9]
<FromGitter> <Blacksmoke16> neat
<FromGitter> <Blacksmoke16> whats preventing `0.35.0` support? Given that's quite near might want to get on that
<FromGitter> <636f7374> @Blacksmoke16 Because Crystal 0.35.0 has not been released yet, Crystal 0.34.0 is installed on my computer.
<FromGitter> <636f7374> @Blacksmoke16 monkey patches.
<FromGitter> <Blacksmoke16> gotcha
chachasmooth has quit [Ping timeout: 260 seconds]
chachasmooth has joined #crystal-lang
<FromGitter> <simonhf> Is there any docs or info explaining why even the simplest Crystal binary is over 100MB in size?
gangstacat has quit [Quit: Ĝis!]
<FromGitter> <Blacksmoke16> that doesnt seem right
<FromGitter> <Blacksmoke16> iv'e never seen one over 10
<FromGitter> <Blacksmoke16> well crystal itself is like 30 something
gangstacat has joined #crystal-lang
<FromGitter> <simonhf> Sorry, my bad... That's, right it's under 2MB :-)
<FromGitter> <simonhf> It's the Alpine docker image that is over 100MB...
<FromGitter> <Blacksmoke16> makes sense
<FromGitter> <jwaldrip> Hey all, if you appreciate the work on https://github.com/crystalshards/crystalshards, please give it a start on github ;-)
rocx has quit [Ping timeout: 260 seconds]
<FromGitter> <simonhf> Gave it a star :-)
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
zorp_ has quit [Ping timeout: 265 seconds]
<raz> 636f7374: 😍
<raz> yay for http/2! this is huge
tdc has joined #crystal-lang
<raz> that h2load snippet in the readme looks mixed up tho.
<raz> if your localhost is _that_ slow you should buy a new computer ;)
alexherbo2 has joined #crystal-lang
oprypin has quit [Quit: Bye]
oprypin has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 260 seconds]
alexherbo2 has joined #crystal-lang
chachasmooth has quit [Ping timeout: 272 seconds]
chachasmooth has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
gangstacat has quit [Ping timeout: 272 seconds]
gangstacat has joined #crystal-lang
Evtimiy has joined #crystal-lang
<Evtimiy> Hello!
<FromGitter> <naqvis> /o
<Evtimiy> Does someone knows how I can access class methods trough macro ?
<Evtimiy> ```
<Evtimiy> ```{{ @type.methods.map &.name.stringify }}``` returns only instance methods
<Evtimiy> `
<Evtimiy> `module CaesarCipher def self.encrypt(string : String) string.chars.map { |char| ((char.upcase.ord - 52) % 26 + 65).chr }.join endend`
<Evtimiy> How can I list the `self.encrypt`method
nowhereFast has joined #crystal-lang
<nowhereFast> assuming a class that includes JSON::Serializable which has a property defined that is of type JSON::Any, when running a to_json on an instance if this class, should this property be affected?
<FromGitter> <naqvis> `@type.class.methods` what will that return?
<FromGitter> <naqvis> what do you mean by "property be affected?" ?
<nowhereFast> rephrasing the question, should calling to_json on a type of JSON::Any add any escaping?
<Evtimiy> @naqvis - `@type.class.methods` will return exactly what I want :) Thank you!
<FromGitter> <naqvis> 👍
<FromGitter> <naqvis> ```code paste, see link``` ⏎ ⏎ you mean sth like this? [https://gitter.im/crystal-lang/crystal?at=5ecf82d39da05a060a37924c]
<nowhereFast> yup
<FromGitter> <naqvis> are you experiencing some problems with generated json?
<nowhereFast> `JSON::Any.new("{\"some\":\"val\"}").to_json` results in `"\"{\\\"some\\\":\\\"val\\\"}\""`
<Evtimiy> nowhereFast, are you trying to assign already generated JSON string to the property ?
<nowhereFast> since JSON::Any already is already json, I'd expect to_json to not have had an effect on it. expected return: `"{\"some\":\"val\"}"`
<Evtimiy> I think that JSON::Any is a wrapper that boxes the actual value and encodes it when is requested
<FromGitter> <naqvis> First of JSON::Any is not what you are treating it like
<FromGitter> <naqvis> it is a Union of JSON Object types
<nowhereFast> Evtimiy, I'd like to have a property of type JSON::Any, as a transient blob of json, which I an pass around as part of a bigger entity, and ultimately call to_json on the whole
<FromGitter> <naqvis> question is how are you getting that `JSON::Any` ?
<FromGitter> <naqvis> if you are getting that via `JSON.parse` then it contained parsed JSON
<FromGitter> <naqvis> if you are creating that manually, then it will wrap the value what you provide to it
<jhass> I think you're looking for (the sadly undocumented) https://crystal-lang.org/api/0.34.0/JSON/Serializable/Unmapped.html
<jhass> if you include that into your class you'll get a json_unmapped property with any not mapped properties
<nowhereFast> ahh.. that might work
<jhass> but looking at the implementation of that, actually declaring a field as JSON::Any should work fine too
<nowhereFast> right, that is what I'd expect
<jhass> so yeah, I guess you're just looking at it wrong in some way
<jhass> https://carc.in/#/r/95r5 this roundtrips just fine
Evtimiy has quit [Remote host closed the connection]
<jhass> nowhereFast: https://carc.in/#/r/95rh this is all the angles I can come up with
Evtimiy has joined #crystal-lang
<Evtimiy> I think that this is what happens - https://play.crystal-lang.org/#/r/95rc
<nowhereFast> I think it's as Evtimiy pointed out earlier, the json blob that comes through already has escaped chars
<jhass> note it's easy to get confused here since JSON looks similar to a namedtuple or hash inspection and inspecting a string puts quotes around and escapes any inner ones
<jhass> but yeah, if you pass a JSON string to JSON::Any that's most likely not what you want
<jhass> note how I sometimes used p and other times puts im my example above
<nowhereFast> yup, it'd have to go through JSON.parse in this case to get the right kind of JSON::Any
<nowhereFast> I was hoping to be able to get away with not having to do any work on the blob at all
<Evtimiy> I'm not sure if there is a way for disabling converting/escaping to JSON for certain fields
<Evtimiy> But if there isn't such way, you can try something else, but I'm not sure that it will be perfect performance-wise
<Evtimiy> You can set your json blob field to a constant and then replace that in the string returned from to_json
<nowhereFast> yup, keep out of the entity and tack it on after to_json is called on it
<nowhereFast> probably the approach for best performance
<nowhereFast> unless json_unmapped could be used
<Evtimiy> Something like that
<nowhereFast> might be able to from_json without specifying a property on the blob
<nowhereFast> though that would be more expensive
<nowhereFast> oh well.. I have options now, thanks folks.
<jhass> ... maybe you just want a String? Not sure I follow really
<Evtimiy> nowhereFast, you are welcome! :)
<Evtimiy> @jhass - I thought of String as well at first, but his string is actually a JSON String and it will be encoded twice
<nowhereFast> jhass, might have just pretzld my mind and you might be right.
* nowhereFast will count escape chars
Evtimiy has quit [Remote host closed the connection]
cloaked1 has quit [Ping timeout: 260 seconds]
cloaked1 has joined #crystal-lang
nowhereFast has quit [Ping timeout: 246 seconds]
zorp_ has joined #crystal-lang
rocx has joined #crystal-lang
lanodan has quit [Quit: WeeChat 2.7.1]
lanodan has joined #crystal-lang
<repo> hi
<FromGitter> <naqvis> /o
<repo> i'm having trouble with XML. I'm reading track points from a GPX file but for whatever reason my xpath always returns an empty node set
<FromGitter> <naqvis> got an example?
<FromGitter> <naqvis> and how does your xml look like?
<repo> i just don't get it..
<FromGitter> <naqvis> i would say XML.parse isn't working
<FromGitter> <naqvis> try `gpx.children.size`
<FromGitter> <naqvis> guess it will return 0
<repo> nope
<repo> it's 1
<repo> it works on xpather
<repo> none of the xpaths work
<repo> i can't even select "//gpx"
<jhass> repo: I bet you're hitting https://github.com/crystal-lang/crystal/issues/9279
<jhass> because of xmlns="http://www.topografix.com/GPX/1/1"
<repo> hm ok
<repo> any workaround?
<repo> until the PR is released
<jhass> let's see
<FromGitter> <naqvis> yeah, that's the problem
<FromGitter> <naqvis> as a workaround, just remove namespace related data `<gpx version="1.1">` and then it should work
<repo> cool thanks!
<repo> jhass: hm i don't know how that applies to the //trkpt xpath
<jhass> exactly the same
<repo> ahh
<repo> yeah
<repo> got it
<repo> /gpx:trkpt
<repo> /
<repo> //
<repo> :)
<jhass> LLVM still amazes me sometimes. I wanted to check if it optimizes a tail call friendly recursive definition into actually doing tail calls. Instead it just rewrites it as a loop
<jhass> yep and does tail calls for more complex ones, nice
<FromGitter> <naqvis> amazing engineering
alexherbo2 has joined #crystal-lang
travis-ci has joined #crystal-lang
<travis-ci> crystal-lang/crystal#aa893b7 (master - Deprecate JSON.mapping and YAML.mapping (#9272)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/692192269
travis-ci has left #crystal-lang [#crystal-lang]
<DeBot> https://github.com/crystal-lang/crystal/pull/9272 (Deprecate JSON.mapping and YAML.mapping)
<FromGitter> <watzon> @blacl
<FromGitter> <watzon> @Blacksmoke16 are all fields on a Granite model nillable by default?
<FromGitter> <Blacksmoke16> yes
<FromGitter> <xmonader> is there something special about forward slash when i want to replace with backslash? ⏎ ⏎ ```path = "Dir1\Dir2\File.txt" ⏎ ⏎ puts path.gsub({"\\": "/"})``` ⏎ ⏎ because I get Dir1Dir2File.txt [https://gitter.im/crystal-lang/crystal?at=5ecff5d0778fad0b13314a92]
<FromGitter> <Blacksmoke16> `path.gsub '\', "/"`
<FromGitter> <Blacksmoke16> er `'\\'`
<FromGitter> <Blacksmoke16> hm
<jhass> >> "Dir1\Dir2\File.txt"
<DeBot> jhass: # => "Dir1Dir2File.txt" - https://carc.in/#/r/95yg
<jhass> the gsub is rather irrelevant
<jhass> >> "Dir1\\Dir2\\File.txt".gsub '\\', '/'
<DeBot> jhass: # => "Dir1/Dir2/File.txt" - https://carc.in/#/r/95yl
<FromGitter> <Blacksmoke16> ah its escaping the `D` and `F`
<FromGitter> <xmonader> wait do i have to make it ⏎ ⏎ ```"Dir1\\Dir2\\File.txt"``` [https://gitter.im/crystal-lang/crystal?at=5ecff7b4225dc25f54b07bdc]
<FromGitter> <xmonader> can't use raw string? with % maybe?
<FromGitter> <Blacksmoke16> `%(Dir1\Dir2\File.txt)` maybe
<FromGitter> <Blacksmoke16> or use https://crystal-lang.org/api/master/Path.html
<FromGitter> <xmonader> @Blacksmoke16 it yields `Dir1Dir2File.txt"` too
<FromGitter> <Blacksmoke16> sec
<FromGitter> <xmonader> @Blacksmoke16 problem is it's a content of a markdown file i'm normalizing
<FromGitter> <Blacksmoke16> `%q(Dir1\Dir2\File.txt)`
<FromGitter> <xmonader> so I don't have a specific input called path, but i'm matching over all the links in a document and making them unixy
<FromGitter> <xmonader> this works beautifully thank you!
<travis-ci> crystal-lang/crystal#05e5f95 (master - Process raises `IO::Error` (or subclasses) (#9340)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/692252865
travis-ci has joined #crystal-lang
travis-ci has left #crystal-lang [#crystal-lang]
<DeBot> https://github.com/crystal-lang/crystal/pull/9340 (Process raises `IO::Error` (or subclasses))
lanodan has quit [Ping timeout: 272 seconds]
lanodan has joined #crystal-lang
renich has joined #crystal-lang
<FromGitter> <simonhf> newbie question: In Perl I can do @array = `my_command` to put the output lines of my_command into an array... Is there an equivalent with crystal?
renich_ has joined #crystal-lang
<FromGitter> <simonhf> sorry, this above lines should have had backticks around the my_command part...
renich has quit [Ping timeout: 256 seconds]
renich_ is now known as renich
<FromGitter> <Blacksmoke16> `array = my_command`?
<FromGitter> <Blacksmoke16> `@array` would denote an instance variable named array. local variables dont need it
<FromGitter> <simonhf> thanks! how does `array = \`my_command\`` know that array should be an array and not a string?
<FromGitter> <simonhf> sorry... not sure how to escape backticks in markdown :-|
<FromGitter> <Blacksmoke16> Crystal has some duck typing
<FromGitter> <Blacksmoke16> the compiler knows `my_command` returns an array and assigns that type to `array`
<FromGitter> <Blacksmoke16> however
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed008dc225dc25f54b0af19]
<FromGitter> <simonhf> In my case my_command is a shell command executed via backticks
<FromGitter> <Blacksmoke16> oh
<FromGitter> <Blacksmoke16> then it would return `"[1,2]"`
<FromGitter> <simonhf> sorry, I had problems with gitter markdown formatting for the actual backticks!
<FromGitter> <j8r> I always dreamed about having `:=` :)
<FromGitter> <Blacksmoke16> to do what?
<FromGitter> <oprypin> ``x`foo``
<FromGitter> <simonhf> cool thanks
<FromGitter> <j8r> @Blacksmoke16 `:=` will force the type of the first assignment
<FromGitter> <simonhf> is there a way to do something like `` `#{my_command}`.each { ...} `` ?
<FromGitter> <Blacksmoke16> `JSON.parse`?
<FromGitter> <simonhf> When I try it, it says "Error: undefined method 'each' for String" ... so does that mean backticks returns a string by default?
<FromGitter> <j8r> @simonhf you can read the API docs here: https://crystal-lang.org/api/master/.
<FromGitter> <Blacksmoke16> `JSON.parse(`#{my_command}`).as_a.each { }`
<FromGitter> <j8r> Basically
<FromGitter> <j8r> why json?
<oprypin> simonhf, it always returns strings yea
<FromGitter> <Blacksmoke16> idk, first thought that came to mind
<oprypin> ```my_command`.each_line``; ```my_command`.split.each`` are some options
<FromGitter> <simonhf> > @simonhf you can read the API docs here: https://crystal-lang.org/api/master/. ⏎ ⏎ I always try to read the docs before posting here :-) The backticks section is short and didn't help me...
<oprypin> sigh
<oprypin> `` `my_command`.each_line``; `` `my_command`.split.each`` are some options
<FromGitter> <j8r> @simonhf the method is usually: ⏎ ⏎ 1) `typeof(var or expression)` ⏎ 2) find the type in api docs to see what it can do [https://gitter.im/crystal-lang/crystal?at=5ed00a24225dc25f54b0b266]
<FromGitter> <Blacksmoke16> depends on what the actual value of the shell command is
<FromGitter> <Blacksmoke16> another thought, whats the shell command. cant just do that in crystal land?
<FromGitter> <simonhf> just produces multiple lines of output
<oprypin> each_line then
<oprypin> u can also iterate over the output in a streaming way
<oprypin> not with backticks, of course, that's just a frowned upon shorthand
<FromGitter> <Blacksmoke16> he's prob writing another 1 liner thing so yea
<FromGitter> <simonhf> > *<oprypin>* each_line then ⏎ ⏎ ooooh that works, thanks! why didn't I try that? :-)
<FromGitter> <j8r> > he's prob writing another 1 liner thing so yea ⏎ ⏎ haha
<FromGitter> <j8r> some have tried one liners in Java - and failed 😆
lanodan has quit [Read error: Connection reset by peer]
travis-ci has joined #crystal-lang
<travis-ci> crystal-lang/crystal#c74ef4b (ci/update - Temp: Update distribution-scripts): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/692283847
travis-ci has left #crystal-lang [#crystal-lang]
lanodan has joined #crystal-lang
renich has quit [Remote host closed the connection]
lanodan has quit [Read error: Connection reset by peer]
renich has joined #crystal-lang
lanodan has joined #crystal-lang
<travis-ci> crystal-lang/crystal#11e7dbc (ci/update - Temp: Update distribution-scripts): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/692286879
travis-ci has left #crystal-lang [#crystal-lang]
travis-ci has joined #crystal-lang
kradnoel has joined #crystal-lang
<FromGitter> <simonhf> > *<oprypin>* `` `my_command`.each_line``; `` `my_command`.split.each`` are some options ⏎ ⏎ thanks for these options!
<FromGitter> <simonhf> > > he's prob writing another 1 liner thing so yea ⏎ > ⏎ > haha ⏎ ⏎ hehe... a rare case where I'm not trying a one liner :-) [https://gitter.im/crystal-lang/crystal?at=5ed016f43ffa6106f1de701b]
<FromGitter> <Blacksmoke16> a two liner? :P
<FromGitter> <simonhf> lol crystal code in its own file!!! <shock> :-)
<FromGitter> <Blacksmoke16> :vince:
alexherbo2 has quit [Ping timeout: 256 seconds]
<FromGitter> <simonhf> And now for the big reveal :-) My first ever Crystal script: ⏎ https://github.com/crystal-lang/crystal/issues/9364#issuecomment-635583884
<FromGitter> <simonhf> I translated the Perl script which I hacked yesterday...
<FromGitter> <simonhf> It actually seems to work... and all comments and critique welcome!
tdc has quit [Ping timeout: 246 seconds]
<FromGitter> <simonhf> this line seems a bit hacky and I'm wondering if there is a better way? `%w(cr cr.exe).each { |s|`
<FromGitter> <Blacksmoke16> add `cr` to the code block
<FromGitter> <Blacksmoke16> for highlighting
<FromGitter> <Blacksmoke16> i.e. ```cr
<FromGitter> <simonhf> done
<FromGitter> <Blacksmoke16> what this doing?
<FromGitter> <Blacksmoke16> just prepending flush_on_newline to stuff?
<robacarp> Just released a minor version of Mosquito, and I think I'd call it stable. This was the one latent bug I knew about and made me nervous, and it's fixed! https://github.com/robacarp/mosquito/commit/b046b35cfbee41aff7f8ef49029c5d53cbad98f1
<FromGitter> <Blacksmoke16> \o/
<robacarp> "I think I'd call it stable _now_"
<FromGitter> <simonhf> 1) prepends the flush thing. 2. creates temporary file with sha256 of one-liner. 3. compiles if not already compiled. 4. deletes older one-liners if too many. 5. runs the compiled one-liner.
<FromGitter> <Blacksmoke16> prob could just do something like
<FromGitter> <Blacksmoke16> is all the caching needed?
<FromGitter> <simonhf> seemed like a nice touch
<robacarp> what are we doing here with all the sha-ing
<robacarp> seems off base with the point of the issue
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/File.html#exists?(path:Path%7CString):Bool-class-method is a thing as well btw
<robacarp> is this because crystal compiling is slow?
<robacarp> > crystal eval 'puts :hi'
<robacarp> 4s 843ms
<FromGitter> <Blacksmoke16> 4s?
<robacarp> second time took 1s 161ms
<robacarp> some sort of filesystetm caching going on probably
<FromGitter> <Blacksmoke16> crystal caches stuff internally
<FromGitter> <Blacksmoke16> so not sure manually doing all that is needed/would add that much perf
<robacarp> but certainly not on a command like that
<robacarp> caching a script eval is dangerous. What if I write `crystal eval 'HTTP.get "google.com"'`
<robacarp> if it's cached, it's not going to run, which is the opposite of what I'm trying to do
<FromGitter> <Blacksmoke16> i think hes caching a build program if it has the same contents
<FromGitter> <Blacksmoke16> i.e. so it would just be built once, otherwise just run the already existing binary
<oprypin> `CRYSTAL_CACHE_DIR=/tmp/a crystal eval "puts :hi"; ls /tmp/a/eval`
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed020b6ff7a920a721a61f0]
<oprypin> ^ those things are being cached, "main" likely excluded. execution is, of course, not cached
<FromGitter> <Blacksmoke16> but crystal does this for you afaik
<robacarp> oh that makes way more sense
<robacarp> what is the default crystal_cache_dir?
<FromGitter> <Blacksmoke16> `~/.cache/crystal/` on mac at least
<FromGitter> <Blacksmoke16> for me, seems it depends on which one of those works ofc
<robacarp> awesome, interesting. So that 4s was probably so long because it was the first time I've ever run crystal eval
<robacarp> completely cold cache
<oprypin> there's even OS-level and CPU-level cache to consider
<robacarp> yeah, wiping ~/.cache/crystal/eval didn't reset the time to 4s, but it went up to 2s
<robacarp> sample size small enough to just be variance in cpu load at time of invocation
<robacarp> my assumption would be that most of that cache is filesystem cache of the crystal compiler
<FromGitter> <Blacksmoke16> could also add `--stats --progress`
<FromGitter> <Blacksmoke16> iirc it says if .o files were reused and stuff
<oprypin> nice
<FromGitter> <simonhf> > https://crystal-lang.org/api/master/File.html#exists?(path:Path%7CString):Bool-class-method is a thing as well btw ⏎ ⏎ Thanks! I saw that and wondered if there is any advantage of `.exists?` over `.file?`? The docs referred to a path instead of file... so I choose `.file?` to be on the safe side :-)
<oprypin> https://crystal-lang.org/api/0.34.0/File.html#file?(path:Path|String):Bool-class-method
<FromGitter> <simonhf> > *<robacarp>* is this because crystal compiling is slow? ⏎ ⏎ Partly, but also because 1. eval does not have all the options that build has for some reason, and 2. writing crystal one liners on the command line, I'd like to be able to type less and maybe have some generic code auto required and/or prepended...
<FromGitter> <simonhf> > i.e. so it would just be built once, otherwise just run the already existing binary ⏎ ⏎ that's right...
<FromGitter> <simonhf> > `~/.cache/crystal/` on mac at least ⏎ ⏎ Seems to be same place on Ubuntu too...
<FromGitter> <simonhf> And when you run crystal eval ... then it creates the folder `~/.cache/crystal/eval/` ... is that a bug? or just a not finished off feature? because it doesn't actually cache anything for eval, or?
<FromGitter> <simonhf> It always takes the same amount of time to build the same eval source code...
<FromGitter> <simonhf> But it's the same for cre.cr too: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ It always takes the same time to build even though `~/.cache/crystal/home-simon-20200526-crystal-cre.cr/` exists... [https://gitter.im/crystal-lang/crystal?at=5ed0287d7da67d06fada45df]
<FromGitter> <simonhf> So it it really 'caching' anything? Or is .cache really a .build folder...
<FromGitter> <Blacksmoke16> what if you clear that folder then try again
<jhass> simonhf: I never even ran this, but some ideas: https://p.jhass.eu/8j.cr
<FromGitter> <simonhf> > what if you clear that folder then try again ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Interesting... you're right... it saves about 1/3rd of the time... so it cache 'a bit'... is that expected? [https://gitter.im/crystal-lang/crystal?at=5ed0292b4412600ccd74648d]
<FromGitter> <Blacksmoke16> prob yea
<FromGitter> <Blacksmoke16> some of the `.o` files get cached
<FromGitter> <Blacksmoke16> if you run with `--progress` you can see
<FromGitter> <Blacksmoke16> `--stats` sorry
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed029c4778fad0b1331e73d]
<FromGitter> <Blacksmoke16> can reuse some `.o` files, im not super familiar with what those are/process around that tho
<FromGitter> <simonhf> > could also add `--stats --progress` ⏎ ⏎ Nice. I updated cre.cr so that it also caches the build log, and has its cache in ~/.cache/cre which seems like a better location...
<jhass> what's your obsession with sprintf/printf btw?
<FromGitter> <watzon> Ok I have to say, this is pretty nice https://github.com/watzon/lucybot/blob/master/src/lucybot/jobs/admin_update.cr
<FromGitter> <simonhf> > *<jhass>* @simonhf: I never even ran this, but some ideas: https://p.jhass.eu/8j.cr ⏎ ⏎ Thanks so much for posting that... gives me a lot of inspiration... I'm going to make some changes! ;-)
<jhass> ah, line 10 needs to be a range for example, 0..-CACHE_SIZE
<jhass> always get confused between the two overloads
<FromGitter> <simonhf> > *<jhass>* what's your obsession with sprintf/printf btw? ⏎ ⏎ just the bad habits of a C programmer :-) but open to alternatives! I noticed you did `Log.debug { "Writing #{body} to #{source_path}" }` ... how would you pad stuff if body was numeric, e.g. `%05d`? And also, does crystal have comma padding, e.g. `%'05d`?
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Number.html#format(separator='.',delimiter=',',decimal_places:Int?=nil,*,group:Int=3,only_significant:Bool=false):String-instance-method
<jhass> things like that, or actually go to formatting for these rare cases, and not invoke sprintf on a single string liteal assignment that doesn't even have any format specifiers in it...
<jhass> and I tend to prefer String#% over sprintf
<FromGitter> <simonhf> > https://crystal-lang.org/api/master/Number.html#format(separator='.',delimiter=',',decimal_places:Int?=nil,*,group:Int=3,only_significant:Bool=false):String-instance-method ⏎ ⏎ So that would be something like e.g. `Log.debug { "bytes=#{bytes.format(...)}" }` ?
<FromGitter> <Blacksmoke16> well if you want bytes
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Int.html#humanize_bytes(precision:Int=3,separator='.',*,significant:Bool=true,format:BinaryPrefixFormat=:IEC):String-instance-method
<jhass> oh, I totally forgot to include the Log.setup_from_env call btw
<FromGitter> <simonhf> > https://crystal-lang.org/api/master/Int.html#humanize_bytes(precision:Int=3,separator='.',*,significant:Bool=true,format:BinaryPrefixFormat=:IEC):String-instance-method ⏎ ⏎ nice :-)
<FromGitter> <simonhf> hmmm... what is the difference between `body << PREAMBEL` and `body += PREAMBEL` ?
<jhass> well for starters body doesn't refer to the same type of object in both cases
<jhass> strings are immutable in crystal, so String#+ creates a new string out of its two operands
<jhass> String.build is smarter here, it allocates a dynamically resizable buffer and yields an IO around it, then returns it as a string
<FromGitter> <simonhf> kk thanks
<FromGitter> <simonhf> > *<jhass>* oh, I totally forgot to include the Log.setup_from_env call btw ⏎ ⏎ How does `Log.setup_from_env` work?
<jhass> https://crystal-lang.org/api/0.34.0/Log.html explains it better than I ever could :)
<FromGitter> <simonhf> Yeah, I'm all over that page... one of the frustrating things about the docs is that they never seem to include any example snippets...
<FromGitter> <Blacksmoke16> Log stuff is changing quite a bit in next version
<FromGitter> <simonhf> like I tried `CRYSTAL_LOG_SOURCES=STDOUT CRYSTAL_LOG_LEVEL=INFO` but nothing happens :-(
<jhass> for basic usecases like above actually not that much
<jhass> forget about LOG_SOURCES, you don't need it here
<jhass> and of course info level does not show debug logs
<FromGitter> <simonhf> kk thanks
<FromGitter> <simonhf> ```Log.debug { "body=#{body}" } ⏎ Log.debug { "path=#{path}" }``` ⏎ ⏎ Is it possible to combine these into one line that outputs two log lines? [https://gitter.im/crystal-lang/crystal?at=5ed034e39da05a060a39a640]
<FromGitter> <Blacksmoke16> Just like that?
<FromGitter> <simonhf> yep
<FromGitter> <Blacksmoke16> No I mean if you want two lines, you just do what you're doing
<jhass> anybody wants to port https://github.com/JoshCheek/seeing_is_believing to Crystal? :D
<FromGitter> <simonhf> something like `%w(body path).each {|s| Log.debug { "s=#{s}" }}` but that actually works... :-)
<FromGitter> <simonhf> this nearly works: `[body, path].each {|s| Log.debug { "s=#{s}" }}`
<FromGitter> <Blacksmoke16> Would need two interloptions
<FromGitter> <Blacksmoke16> Of s
<FromGitter> <j8r> jhass the closest for now is https://github.com/Sija/debug.cr
<FromGitter> <simonhf> > Of s ⏎ ⏎ How would that work?
<FromGitter> <simonhf> I tried `["body", body, "path", path].each {|s,v| Log.debug { "s=#{v}" }}` but each only provides one argument...
<jhass> j8r: the nice thing about seeing_is_believing is that it's designed such that it can run in the editor and replace the buffer contents. Watch how he uses it in the video, that's what I'm talking about, it basically turns your editor into an interactive repl
<jhass> maybe we should have Log.p! and Log.pp!
<FromGitter> <j8r> Yeah... would not be easy to do in Crystal
<jhass> crystal playground does it basically
<jhass> crystal play I mean
<FromGitter> <Blacksmoke16> > *<jhass>* maybe we should have Log.p! and Log.pp! ⏎ ⏎ eh, a better case would be to use these as metadata
<FromGitter> <j8r> With compiler knowledge, may be it is not hard - don't know
<FromGitter> <simonhf> given a variable, is there a way to introspect at run-time and get its text name?
<oprypin> no..?
<jhass> no, that's why we have macros
<oprypin> i mean, if you're referring to a variable, you have its text name right there. just instead of `a` write `"a"`
<FromGitter> <simonhf> aaah... kk
<FromGitter> <simonhf> how would I add the macro to this line? `[body, path].each {|s| Log.debug { "s=#{s}" }}`
<FromGitter> <Blacksmoke16> :thinking:
<FromGitter> <Blacksmoke16> prob be a better design to do (0.35.0) `Log.debug &.emit(body: body, path: path)`
<FromGitter> <Blacksmoke16> or `Log.debug &.emit("Running command", body: body, path: path)`
<oprypin> `{% for v in ["body", "path"] %}; Log.debug { "#{{{v}}}={{v.id}} }; {% end %}`
<FromGitter> <j8r> btw don't abuse macros
<oprypin> the idiomatic thing here would indeed be to just write 2 lines
<FromGitter> <j8r> harder to debug, longer compile times
<FromGitter> <simonhf> yeah, but I want to have a longer list of stuff...
<FromGitter> <simonhf> unfortunately the macro line gives errors... trying to debug it... :-)
<oprypin> simonhf, fyi for trying things out this functionality is built-in (just not using `Log`): `p! body, path`
<jhass> or pp! for pretty printing
<FromGitter> <simonhf> thanks
<oprypin> >> body = "a"; path = 6; p! body, path
<FromGitter> <Blacksmoke16> if all you need is to print to STDOUT the you'd be better off doing something like
<DeBot> oprypin: body # => "a" - more at https://carc.in/#/r/9604
<FromGitter> <Blacksmoke16> ```def log(*args) ⏎ p! Time.utc, *args ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5ed038f9549761730b6432fc]
<FromGitter> <simonhf> yep... this line is causing errors: `{% for v in ["body", "path"] %}`
<FromGitter> <Blacksmoke16> assuming you were using Log for the timestamp...
<oprypin> no seems fine
<oprypin> >> require "log"; body = "a"; path = 6; {% for v in ["body", "path"] %} Log.debug { "#{{{v}}}={{v.id}}" }; {% end %}
<DeBot> oprypin: # => nil - https://carc.in/#/r/9609
<FromGitter> <phase858> I'm probably being an idiot here, but whats the escape prefix for ansi escape sequences?
<oprypin> the what what
<FromGitter> <phase858> ansi sequences, stuff like ``\e[H\e[2J``, but the ``\e`` bit seems to not be working for me
<oprypin> u mean `\e` which is `\x1b`
<oprypin> p! "\e", "\x1b"
<oprypin> no i think both work
<jhass> yeah, both work
<FromGitter> <phase858> huh, odd, since I can't seem to get the arrow key sequences to detect with \e
<jhass> could do \u1b too I guess xD
<oprypin> *detect*?
<FromGitter> <phase858> need implement a command history for a thing
<oprypin> libreadline?
<FromGitter> <simonhf> The original one had no closing quote... mystery solved :-)
<FromGitter> <phase858> I mean I have the rest of it done
<oprypin> simonhf, ah yea that was an error just not in the place you indicated, so i didnt suspect that i should point that out
<FromGitter> <phase858> just can't seem to get gets to accepts ``\e[A`` and such
<oprypin> `STDIN.raw` might be the key to success there?
<FromGitter> <simonhf> interestingly the eval code compiles but nothing comes out: `CRYSTAL_LOG_LEVEL=DEBUG crystal eval 'require "log"; body = "a"; path = 6; {% for v in ["body", "path"] %} Log.debug { "#{{{v}}}={{v.id}}" }; {% end %}'`
<oprypin> presumably cuz Log.debug is silent by default?
<FromGitter> <simonhf> I guess somehow the env var is not getting passed down?
<oprypin> oh nvm you set the level. maybe something wrong there, yea
<FromGitter> <Blacksmoke16> missing `Log.setup_from_env`
<oprypin> yea
<oprypin> simonhf, `LOG_LEVEL=DEBUG cr eval 'require "log"; Log.setup_from_env; body = "a"; path = 6; {% for v in ["body", "path"] %} Log.debug { "#{{{v}}}={{v.id}}" }; {% end %}'`
<oprypin> woops, that `cr` is my alias for crystal@master
<oprypin> current one is `CRYSTAL_LOG_LEVEL=DEBUG crystal eval 'require "log"; Log.setup_from_env; body = "a"; path = 6; {% for v in ["body", "path"] %} Log.debug { "#{{{v}}}={{v.id}}" }; {% end %}'`
<FromGitter> <simonhf> true true thanks
<FromGitter> <simonhf> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed03bafa91f120a6ccca5f9]
<FromGitter> <simonhf> this reveals that the macro is not quite working...
<FromGitter> <phase858> stdin.raw did it
<FromGitter> <Blacksmoke16> is using Log worth it in this context?
<FromGitter> <Blacksmoke16> not really getting much
<FromGitter> <simonhf> It's useful for me to learn about log and macros :-)
<FromGitter> <simonhf> @oprypin any ideas?
<FromGitter> <Blacksmoke16> `"#{{{v}}}=#{{{v.id}}}"`
<oprypin> yes that's correct; sorry about that
<FromGitter> <simonhf> thanks! I think I get now: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed03d0d2280c80cbfd5adb5]
<FromGitter> <simonhf> for debugging macros, is there a way to get crystal to output the source code after the macro is evaluated?
<FromGitter> <Blacksmoke16> `{{debug}}`
<FromGitter> <simonhf> thanks! where does that go?
<FromGitter> <Blacksmoke16> like can do
<oprypin> `{% begin %} {% for v in ["body", "path"] %} Log.debug { "#{{{v}}}=#{{{v.id}}} }; {% end %} {% debug %} {% end %}`
<FromGitter> <Blacksmoke16> ```{% being %} ⏎ {% for x in y %} ... {% end %} ⏎ {{debug}} ⏎ {% end %}``` [https://gitter.im/crystal-lang/crystal?at=5ed03d9f2280c80cbfd5aea3]
<FromGitter> <Blacksmoke16> `begin`
<FromGitter> <simonhf> Very nice: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed03e1e225dc25f54b13ba6]
kradnoel has quit [Read error: Connection reset by peer]
kradnoel has joined #crystal-lang
<FromGitter> <j8r> Using crystal eval for code snippets is not really readable you know...
<FromGitter> <simonhf> I guess it's what you get used to? :-
<FromGitter> <simonhf> :-)
<FromGitter> <watzon> Ok there is definitely a std bug somewhere. I keep getting this: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ they happen with the same code at different times, and only when trying to make an HTTP request from a fiber [https://gitter.im/crystal-lang/crystal?at=5ed03faf4412600ccd7498c7]
<FromGitter> <watzon> Fml this is making life difficult
<FromGitter> <simonhf> are those ??? stack corruption or something else?
<FromGitter> <watzon> Probably unreadable symbols in the stack. I know there's a PR that got merged that's supposed to help with that.
<FromGitter> <j8r> @simonhf everybody properly humans reads better with a formatted code which doesn't have lines of +200 chars
<FromGitter> <simonhf> 'properly human' lol :-)
<FromGitter> <j8r> you might be not haha? Only computers like minified code put on a single line to parse faster
<straight-shoota> @watzon, seems like this is erroring inside libssl
<FromGitter> <watzon> Yeah, but it only happens in one specific case. When creating a HTTP::Client request from within a running fiber. Idk what's going on, but it's driving me crazy.
<FromGitter> <simonhf> Running out of stack space?
<FromGitter> <j8r> you are not using mt @watzon ?
<FromGitter> <watzon> Not currently. I could try and see if it helps.
<FromGitter> <j8r> Not really
<FromGitter> <j8r> It you were using mt, it could be something related to thread safety
<FromGitter> <watzon> Nope it doesn't
<FromGitter> <watzon> Yeah it's not
<FromGitter> <watzon> It's weird, because sometimes I get that huge stack trace, and other times I just get ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed041d7ff7a920a721abae0]
<FromGitter> <j8r> I got this one time
<FromGitter> <simonhf> Stack corruption affecting the stack trace size?
<FromGitter> <j8r> Does it happen when you do a lot of request?
<FromGitter> <watzon> Yeah
<FromGitter> <watzon> I'm polling and attempting to run another command at the same time
<FromGitter> <watzon> Normally it isn't an issue, but as soon as I try to make a request inside of a thread it blows up
travis-ci has joined #crystal-lang
<travis-ci> crystal-lang/crystal#290a5f9 (master - CI: Use --json-config-url doc option (#9370)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/692355069
travis-ci has left #crystal-lang [#crystal-lang]
<DeBot> https://github.com/crystal-lang/crystal/pull/9370 (CI: Use --json-config-url doc option)
<FromGitter> <j8r> I got this malloc issue because I used the same `HTTP::Client` instance for all requests
<FromGitter> <j8r> One instance has to be created for each
<FromGitter> <watzon> Hmm
<FromGitter> <watzon> Go figure, that works. So the problem is attempting to use the same HTTP::Client across fibers.
<FromGitter> <j8r> yes
<FromGitter> <j8r> and if performance matters, you could use a connection pool
<FromGitter> <j8r> I did open https://forum.crystal-lang.org/t/generic-connection-pool-merge-projects/2116 - at the end nothing new
<travis-ci> crystal-lang/crystal#67d4731 (master - Merge pull request #9366 from asterite/bug/autocast-union-alias-default-value): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/692356316
travis-ci has left #crystal-lang [#crystal-lang]
travis-ci has joined #crystal-lang
<DeBot> https://github.com/crystal-lang/crystal/pull/9366 (Make autocasting work in default values against unions)
<FromGitter> <watzon> Yeah I'll add an issue in my own repo to check in on the state of connection pools later
<FromGitter> <j8r> I would like to have a pool that can grow and ungrow dynamically
<FromGitter> <j8r> depending of the load - but no time to work on a pool 😅
<FromGitter> <watzon> Yeah that would certainly be ideal
<FromGitter> <j8r> Some basic algo, trying to always keep a margin of 5 connections not used
<FromGitter> <j8r> I see more and more people talking about the 1.0 - does it mean it will be released soon?
<FromGitter> <j8r> I risk to guesstimate for 1 year
<FromGitter> <watzon> The last blog post made it seem like it
kradnoel has quit [Remote host closed the connection]
<oprypin> j8r, nono it's real, like could literally be the next release after 0.35
<FromGitter> <j8r> ...really? :O
<oprypin> but it's just a feeling from the comments that pop up from core team
<FromGitter> <j8r> I doubt
<oprypin> dont u see the cleanups
<FromGitter> <j8r> Yeah I know it is preparing
<oprypin> significant breaking changes are already considered unacceptable
<FromGitter> <watzon> I didn't think it would happen quite that soon. I was thinking maybe around 0.37.0-0.38.0.
<FromGitter> <j8r> But I really doubt a 1.0 release will be out without finishing a basic Windows support
<FromGitter> <watzon> Windows support isn't close enough yet is it?
<FromGitter> <j8r> I don't worry much about Debug and MT (points from the blog)
<oprypin> j8r, well they're gonna do it
<oprypin> i wish they didnt without windows support but here we are
<oprypin> my bet is 0.36 then 1.0
<FromGitter> <j8r> Normally each release can up to ~3months (sometimes 2)
<FromGitter> <j8r> and it can be even longer till 1.0
<FromGitter> <j8r> The sooner would be 6 months, at the very least. More realistically, ~1 year
<FromGitter> <j8r> oprypin you code (or had?) with nim, they released 1.0 quite recently
<oprypin> no i don't know about nim
<oprypin> j8r, my bet is 4 months
<FromGitter> <watzon> Yeah nim is even older than Crystal iirc. Not by a lot.
<oprypin> 1.0 wouldn't be a big release logically
<FromGitter> <j8r> I highly suspect a comeback of beta/pre releases
<FromGitter> <j8r> 4months seems very rapid IMHO
<FromGitter> <j8r> anyway, will see
<FromGitter> <mattrberry> How would I go about passing a function pointer to a c binding? I can't seem to get my code to compile...
<FromGitter> <watzon> You need a pointer to a proc
<FromGitter> <watzon> As far as the C binding itself
<FromGitter> <watzon> Just a sec
<FromGitter> <mattrberry> So for passing a callback to this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed049044c9b0f060d2e3c45]
<FromGitter> <mattrberry> Would something like this be the correct approach? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed049359da05a060a39d7a5]
<FromGitter> <mattrberry> When I add that callback, I immediately stack overflow before printing "test"
<FromGitter> <simonhf> `[2020-05-28T23:47:27.444090000Z #66625]` is it possible to configure the logger so that the timestamp has a different format?
<FromGitter> <simonhf> thanks for all the suggestions earlier! I have taken them on-board and come up with a version 2: ⏎ https://github.com/crystal-lang/crystal/issues/9364#issuecomment-635676769
<FromGitter> <Blacksmoke16> such as?
<FromGitter> <Blacksmoke16> also not sure im a fan of using Log for this
<FromGitter> <Blacksmoke16> not getting much benefit over `puts`
<FromGitter> <Blacksmoke16> or even a single method that adds some common data to each `puts`