ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.29.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
lucasb_ has quit [Quit: Connection closed for inactivity]
chimkan has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
chimkan has quit [Client Quit]
laaron has quit [Client Quit]
laaron has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
_whitelogger has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <Nbotz> how can i return the minute and second of Time.now in integer?
<FromGitter> <Nbotz> i know i can do it through `to_s`, but then i cant do arithmetic
<FromGitter> <watzon> What exactly do you mean @Nbotz?
<FromGitter> <watzon> How do you want the minute and second together if not as a string?
<FromGitter> <Nbotz> like
<FromGitter> <Nbotz> like `1545` with 15 being the minutes and 45 being the seconds
<FromGitter> <Nbotz> but as an integer so i can do arithmetic
<FromGitter> <Nbotz> im trying to find the offset between the initial time, and the updated time, but seconds reset after 60, and minutes are too short to increment
<FromGitter> <watzon> Ok...
<FromGitter> <watzon> Well this will give you what you want
<FromGitter> <watzon> ```Time.now.to_s("%M%S").to_i```
<FromGitter> <watzon> Are you trying to time execution time? Like a stopwatch?
<FromGitter> <Nbotz> oh, i had to use `to_i` in `Time.now`
<FromGitter> <Nbotz> yeah, im timing the time the server starts to the time a new client enters the server
<FromGitter> <watzon> You know that you can just do arithmatic with `Time` right?
<FromGitter> <Nbotz> would using the whole time be better than just the minute and second?
<FromGitter> <watzon> Look into `Time::Span`
<FromGitter> <watzon> Actually devdocs is outdated
<FromGitter> <watzon> Don't know that anything has been changed with `Time::Span` though
<FromGitter> <Nbotz> thanks, but the `to_s("%M%S").to_i` works best for right now, thanks for your help
<FromGitter> <watzon> You can initialize a `Time.now` when the process starts, a `Time.now` when it ends, and then subtract the first one from the second one. It's going to be much less error prone.
<FromGitter> <watzon> The string to int method is going to be janky
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <Nbotz> the thing is, it returns a time, when i need a single int
<FromGitter> <Nbotz> and if i single it out to `time.seconds` then i get the same problem i had before
<FromGitter> <watzon> It returns a `Time::Span`
<FromGitter> <Nbotz> yes, im calculating two `Time::Span` and it returns a `Time::Span` but i need it to return an int
<FromGitter> <Nbotz> https://play.crystal-lang.org/#/r/72ip as an example
<FromGitter> <watzon> This is the process you need: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d034223a8d9871b32844e9f]
<FromGitter> <watzon> `Time::Span#total_seconds` will give you the total amount of seconds that has elapsed since the process started
<FromGitter> <Nbotz> ah it worked
<FromGitter> <Nbotz> yeah that works best, thanks i see now
<FromGitter> <watzon> It's always best to work with the language :)
<FromGitter> <Nbotz> crystal is surprisingly accommodating. i never knew about the timespan stuff
flaviodesousa has quit [Quit: KVIrc 4.9.3 Aria http://www.kvirc.net/]
gangstacat has quit [Ping timeout: 258 seconds]
ashirase has quit [Ping timeout: 245 seconds]
ashirase has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
gangstacat has joined #crystal-lang
laaron- has joined #crystal-lang
laaron has quit [Remote host closed the connection]
devil_tux has joined #crystal-lang
devil_tux has quit [Ping timeout: 248 seconds]
devil_tux has joined #crystal-lang
duane has joined #crystal-lang
alex`` has joined #crystal-lang
<FromGitter> <Prutheus> How to convert a String `"2"` to `"02"` (adding leading 0's) ?
<jokke> Prutheus: "2".rjust(2, '0')
<jokke> `"2".rjust(2, '0')`
alex`` is now known as alexherbo2
alexherbo2 is now known as alex``
laaron- has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
duane has quit [Ping timeout: 248 seconds]
Creatornator has joined #crystal-lang
duane has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
alex`` has quit [Ping timeout: 245 seconds]
alex`` has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
duane has quit [Ping timeout: 245 seconds]
return0e has joined #crystal-lang
return0e_ has quit [Ping timeout: 258 seconds]
duane has joined #crystal-lang
BaldEagleX02 has joined #crystal-lang
moei has joined #crystal-lang
duane has quit [Ping timeout: 245 seconds]
<pracabor> is it not (yet) possible to chain iterators in Crystal? I'm trying `array.each_slice(8).map {...}` and getting an error.
<pracabor> in ruby, eg: ` "abcdefghijklmnop".split('').each_slice(8).map(&:join) => ["abcdefgh", "ijklmnop"]`
<FromGitter> <jwoertink> With a HTTP::Handler, if the `call` doesn't return `call_next`, what *should* it return? `context`?
<FromGitter> <jwoertink> @Nbotz If you're measuring time, you can also use `elapsed_time = Time.measure do`
<FromGitter> <jwoertink> https://crystal-lang.org/api/0.29.0/Time.html#measure%28%26block%29%3ATime%3A%3ASpan-class-method
<FromGitter> <jwoertink> pracabor, I don't think that's supported yet
<pracabor> @jwoertink Amber frequently returns a HTTP::Context from the #call method, eg: https://github.com/amberframework/amber/blob/149f103ce264a21744c150e20dc677f3d850a33b/src/amber/pipes/logger.cr#L23
<pracabor> (I can't make any statement about the correctness of this behavior, but it is at least _working_)
<FromGitter> <jwoertink> ah, cool. That's what I thought
<FromGitter> <bew> pracabor it works pretty well for me https://carc.in/#/r/72mx
<FromGitter> <pynixwang> method arg annotation implemented?
alex``` has joined #crystal-lang
<FromGitter> <r00ster91> yep: `def method(arg : String)` if you mean that
alex`` has quit [Ping timeout: 268 seconds]
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
alex``` has quit [Ping timeout: 246 seconds]
alex``` has joined #crystal-lang
<Yxhuvud> pracabor: works fine. `p "abcdefghijklmnop".split("").each_slice(8).map(&.join).to_a`
<FromGitter> <watzon> His problem is this `.map(&:join)`
<FromGitter> <watzon> It needs to be `.map(&.join)`
flaviodesousa has joined #crystal-lang
flaviodesousa has quit [Client Quit]
Creatornator has joined #crystal-lang
alex``` has quit [Ping timeout: 245 seconds]
alex``` has joined #crystal-lang
alex``` has quit [Ping timeout: 248 seconds]
alex``` has joined #crystal-lang
alex```` has joined #crystal-lang
alex``` has quit [Ping timeout: 245 seconds]
alex`` has joined #crystal-lang
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
alex```` has quit [Ping timeout: 246 seconds]
alex`` has quit [Ping timeout: 244 seconds]
alex`` has joined #crystal-lang
Creatornator has joined #crystal-lang
duane has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<pracabor> @bew thanks for that, I'm obviously doing something wrong: https://carc.in/#/r/72o7
<FromGitter> <tenebrousedge> '0' is a char
<FromGitter> <tenebrousedge> "0" is a string
<FromGitter> <tenebrousedge> and array(char) doesn't have `rjust`
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<pracabor> the problem is where the `p` is
<pracabor> this doesn't work: https://carc.in/#/r/72og
<pracabor> but this does: https://carc.in/#/r/72oi
<pracabor> @tenebrousedge rjust wants a char, not a string, but I also had a missing .join("") in there
<pracabor> anyway, that might represent a bug in the compiler of some sort, but I have it working now. thanks for looking
<FromGitter> <tenebrousedge> how about https://carc.in/#/r/72oq
<FromGitter> <watzon> Much nicer looking
<pracabor> that does run, but I disagree about it being readable
<pracabor> but thats personal preference
<FromGitter> <tenebrousedge> `&:join` isn't particularly readable until one becomes more familiar with Ruby
<FromGitter> <tenebrousedge> `&.` is a Crystal-ism
Creatornator has joined #crystal-lang
<FromGitter> <watzon> `&.` makes more sense imo
<FromGitter> <tenebrousedge> I was pained to see the reaction of the Ruby community to the idea of introducing that syntax to Ruby
<FromGitter> <wernerj> As a rubyist new to Crystal, &: makes more sense to me.
<FromGitter> <Blacksmoke16> how you figure?
<FromGitter> <Blacksmoke16> `.` is more clear its just a method call
<FromGitter> <Blacksmoke16> where in both cases `&` just represents each item in the array
<FromGitter> <watzon> Exactly
<FromGitter> <wernerj> I see it a shortcut for .send(:method)
<FromGitter> <tenebrousedge> I wouldn't mind both being available. Ruby's fundamental method is `send`, and the object model is based on the idea that methods are just signals to objects, which can respond to those methods as they choose
<FromGitter> <Blacksmoke16> time to unlearn some Ruby :P
<FromGitter> <watzon> I don't think we'll ever see `Object#send` in Crystal
<FromGitter> <tenebrousedge> but `&:` is actually a shortcut for `to_proc`, not `send`
<pracabor> I most definately flunked out of a ruby interview a couple years ago because I couldn't remember it was &: instead of &.
ua_ has joined #crystal-lang
<FromGitter> <tenebrousedge> there are probably good reasons for not having `send` in Crystal
ua has quit [Ping timeout: 244 seconds]
<FromGitter> <watzon> I'm fairly certain there are, I can't remember the exact reasoning though
<FromGitter> <tenebrousedge> you could probably implement it as a macro?
<FromGitter> <Blacksmoke16> you can
<FromGitter> <Blacksmoke16> is the corresponding issue
rohitpaulk has quit [Ping timeout: 245 seconds]
<alex``> what is the way to read a project config.yml?
<alex``> src/foo.cr
<alex``> I want to read config/foo.yml
<FromGitter> <Blacksmoke16> based on the name of the cr file?
<alex``> no
<alex``> I wonder when the file is read
<alex``> is it when executing the binary
<FromGitter> <Blacksmoke16> can either do it at runtime or compile time
<FromGitter> <Blacksmoke16> depends what method you use
<alex``> or the contents of the yaml is in memory
<FromGitter> <Blacksmoke16> can either use like `YAML.parse(File.read "path/to/config.yml")`
<FromGitter> <Blacksmoke16> or ideally have a struct/class that defines the structure, then can do `Config.from_yaml File.read "path/to/config.yml"`
<alex``> path/to/config.yml, if relative, for example 'config.yml'
<alex``> it will read depending of the cwd?
<alex``> I guess it is not what I want
<FromGitter> <Blacksmoke16> iirc its relative to the location of the executing file?
<FromGitter> <Blacksmoke16> i dont really remember
<alex``> either relative to the project root directory or in-memory
<FromGitter> <Blacksmoke16> there is a `read_file` macro which would include the contents as a string at compile time
<alex``> for example in src/foo/bar/baz/qux.cr
<alex``> how I get the config/foo.yml easily
<alex``> don’t get if it's relative to qux.cr here
<alex``> or the cwd
<FromGitter> <Blacksmoke16> did you try just doing `File.read "config/foo.yml"`?
<alex``> not yet
<FromGitter> <Blacksmoke16> id just try that and go from there
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
alex`` has quit [Ping timeout: 258 seconds]
alex`` has joined #crystal-lang
Creatornator has joined #crystal-lang
duane has quit [Ping timeout: 248 seconds]
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <Nbotz> is there any way to calculate the duration of a video in crystal?
<FromGitter> <Nbotz> ffmpeg doesnt return anything
<FromGitter> <tenebrousedge> ffmpeg -i doesn't return the duration? what kind of video is this?
<FromGitter> <Nbotz> webm
<FromGitter> <Nbotz> maybe i just didnt call it correctly? i just used `ffmpeg -i #{v} 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,// | sed 's@\..*@@g' | awk '{ split($1, A, ":"); split(A[3], B, "."); print 3600*A[1] + 60*A[2] + B[1] }'`
<FromGitter> <tenebrousedge> where are the webm files coming from?
<FromGitter> <Nbotz> video folder on server
<FromGitter> <Nbotz> public/videos
<FromGitter> <tenebrousedge> are they being generated by some process?
<FromGitter> <Nbotz> no, but `Dir.children` is called on every page refresh to load new videos from the folder
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang