RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.24.1 | 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
faustinoaq has quit [Quit: IRC client terminated!]
faustinoaq has joined #crystal-lang
A124 has joined #crystal-lang
A124 has quit [Ping timeout: 245 seconds]
<watzon> Turns out I didn't need that after all. I just created a macro that wraps JSON.mapping but also creates an initializer and supports extending other classes with mappings.
<hightower3> Who can tell me why this produces a Time object with date in year 48, instead of 2017? https://carc.in/runs/3nel.cr
<watzon> This is the URL we need https://carc.in/#/r/3nel
<FromGitter> <bew> https://carc.in/#/r/3nen
duane has quit [Remote host closed the connection]
duane has joined #crystal-lang
<hightower3> ys but why seconds: , nanoseconds: doesn't work
RX14 has quit [Quit: Fuck this shit, I'm out!]
RX14 has joined #crystal-lang
<FromGitter> <bew> look at the implementation
<FromGitter> <bew> I think that using seconds directly doesn't start from the UNIX initial year (1969), but starts at year 0
<FromGitter> <bew> so you get 48 years, instead of 1969 + 48
<watzon> I think you're right @bew
<hightower3> that's it. Thanks
<FromGitter> <bew> the source code is always right :P
A124 has joined #crystal-lang
<RX14> @hightower3, you need to use Time.epoch for that
<RX14> @hightower3, https://crystal-lang.org/api/master/Time.html#epoch(seconds:Int):Time-class-method
<hightower3> RX14, yes but I also need to provide nanoseconds
<RX14> uhh
<RX14> you're pretty much stuck using Time::UNIX_SECONDS then
<watzon> Does anyone know of something like https://github.com/dkubb/equalizer for Crystal?
<RX14> @hightower3, or just `Time.epoch(0) + Time.new(seconds, nanoseconds)`
<RX14> that's unlikely to be a measurable performance impact
<hightower3> hehe nice one. UNIX_SECONDS will do
<FromGitter> <aisrael> @watzon I think that’d be hard to do without reflection. Unless you use macros, but then that may tie down the rest of your class’ implementation
<RX14> @hightower3, keep in mind UNIX_SECONDS isn't in the docs so it could go away
<hightower3> Seems like I need Time.epoch(0).epoch
<watzon> That's what I was afraid of
<watzon> Are we working on getting reflection into Crystal?
<RX14> no, because we have macros
A124 has quit [Ping timeout: 260 seconds]
<hightower3> actually not .epoch, but something else.....
<hightower3> RX14, I'm not sure that Time.epoch(0) works because the argument to seconds: needs to be an int, and I can't get the absolute amount of seconds out of Time object. And I also can't do t = Time.epoch(0) + Time.new( seconds: ... ) because Time only supports adding a span to it
<hightower3> Not sure if I'm missing something, but using UNIX_SECONDS seems like the only choice
<RX14> oh
<RX14> that was just a typo
<RX14> s/Time/Time::Span/
<RX14> and it'll work
<RX14> `Time.epoch(0) + Time::Span.new(seconds, nanoseconds)`
faustinoaq has quit [Quit: IRC client terminated!]
A124 has joined #crystal-lang
<hightower3> Now the timezone is causing me problems, somewhere it's getting honored
<hightower3> (where previously it wasn't)
A124 has quit [Ping timeout: 256 seconds]
rohitpaulk has joined #crystal-lang
A124 has joined #crystal-lang
<hightower3> time to give up
A124 has quit [Ping timeout: 268 seconds]
<hightower3> Looks like Time::Kind::Unspecified isn't unspecified but honors time zone
rohitpaulk has quit [Ping timeout: 256 seconds]
rohitpaulk has joined #crystal-lang
A124 has joined #crystal-lang
A124 has quit [Ping timeout: 240 seconds]
A124 has joined #crystal-lang
<FromGitter> <aisrael> So, um `NamedTuple` has `#has_key?` but the compiler doesn’t seem to recognize that and can’t guarantee that when the key is fetched, it has a value?
A124 has quit [Ping timeout: 252 seconds]
A124 has joined #crystal-lang
A124 has quit [Ping timeout: 245 seconds]
A124 has joined #crystal-lang
A124 has quit [Ping timeout: 240 seconds]
A124 has joined #crystal-lang
A124 has quit [Ping timeout: 240 seconds]
A124 has joined #crystal-lang
<FromGitter> <bew> is there a dummy IO object, like IO::Memory that blocks the current fiber when reading on it, until another fiber writes to it? (usecase: write test cases for a concurrent app that reads on an IO, and I'd like to write to this dummy IO in my tests)
A124 has quit [Ping timeout: 245 seconds]
<bmcginty> bew: Could you use IO.pipe?
<FromGitter> <bew> ah yes maybe, that's a good idea
A124 has joined #crystal-lang
A124 has quit [Ping timeout: 240 seconds]
hightower2 has joined #crystal-lang
A124 has joined #crystal-lang
hightower3 has quit [Ping timeout: 240 seconds]
A124 has quit [Ping timeout: 240 seconds]
rohitpaulk has quit [Ping timeout: 260 seconds]
A124 has joined #crystal-lang
A124 has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
A124 has joined #crystal-lang
A124 has quit [Ping timeout: 260 seconds]
<watzon> Does anyone know the correct way to parse time formatted like this "Mon Jul 16 12:59:01 +0000 2007"
rohitpaulk has quit [Ping timeout: 245 seconds]
<watzon> Every time I try to parse that string I get the error `Expecting number`
<crystal-gh> [crystal] woodruffw opened pull request #5754: File: Add `File.append` (master...file-append) https://git.io/vA6OA
duane has quit [Ping timeout: 256 seconds]
duane has joined #crystal-lang
<watzon> I guess it's this "%a %b %d %T %z %Y"
rohitpaulk has joined #crystal-lang
<FromGitter> <bew> not sure where to search about this: Is there a concept difference between a Decoder & a PullParser?
A124 has joined #crystal-lang
A124 has quit [Ping timeout: 268 seconds]
<FromGitter> <bew> And also, is there a simple way to get the bytesize of a number? (so a Int32 would give 4, a Int16 would give 2, ..)
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <bew> oh yes!!! I forgot this one thank you!
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 256 seconds]
jnyw has joined #crystal-lang
rohitpaulk has joined #crystal-lang
bonemind has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 252 seconds]
jnyw has quit [Ping timeout: 248 seconds]
<FromGitter> <philfine> Can I expect the UInt64 would overflow as in C
<FromGitter> <philfine> Works as expected
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
<crystal-gh> [crystal] bmmcginty opened pull request #5755: [WIP] Add SNI support to OpenSSL::SSL::Context::Server. (master...ssl_server_sni) https://git.io/vA6KV
rohitpaulk has joined #crystal-lang
maattdd_ has joined #crystal-lang
<FromGitter> <j8r> hi, what is the best way to split a string according two character?
<FromGitter> <aisrael> @j8r You mean like `”foo, bar”.split(“, “) #=> [“foo”, “bar”]`?
alex`` has joined #crystal-lang
Papierkorb has joined #crystal-lang
Papierkorb has left #crystal-lang ["Konversation terminated!"]
<FromGitter> <j8r> @aisrael I mean a thing like `"a b\t c".split(' ', '\t') "=> ["a", "b", "c"]`, without regexes
<FromGitter> <aisrael> Oh. Well, I don’t understand why you’re trying to avoid regex when `”a b\tc”.split(/[ \t]/)` works great.
daemonwrangler has quit [Quit: ZNC 1.6.5 - http://znc.in]
daemonwrangler has joined #crystal-lang
<FromGitter> <j8r> yes but not really optimized, i try to avoid regex when creating a parser
bonemind has quit [Ping timeout: 240 seconds]
bonemind has joined #crystal-lang
<FromGitter> <j8r> by the way I've found a way to do why I what, I will squeeze the tabs
<FromGitter> <aisrael> If you’re creating a parser, then shouldn’t you be using the lexer to split out all your tokens for you?
<FromGitter> <j8r> that's what I'm doing with this expression, but I've succeed by squeezing tabs
<FromGitter> <j8r> this is a Caddyfile parser :)
<FromGitter> <philfine> What is the class to use to store N elements in a list and get the median one
<FromGitter> <philfine> Something like a sorted list
<FromGitter> <aisrael> Is there a `SortedList`? Even if there were, wouldn’t it be more efficient to just `list.sort[list.size/2]`?
<FromGitter> <philfine> Never did this sort of things in ruby either :D
<FromGitter> <philfine> Don't really know
<FromGitter> <philfine> If it is an abstraction through balanced tree, no
<FromGitter> <philfine> It is way less efficient the array
<FromGitter> <philfine> I would say
<FromGitter> <philfine> But it all depends on the implementation
<FromGitter> <aisrael> I mean, with a sorted list (or array) you’d essentially have to sort upon every insertion. A quick `.sort` on an existing array would be more efficient.
<FromGitter> <philfine> I will be getting this median on every insertion, in that sense I am sorting when adding
<FromGitter> <philfine> What I can do is extend array to insert, ordered
<FromGitter> <aisrael> Ahh… if you need to get the median upon every insertion, then I guess insertion sort is your friend.
rohitpaulk has quit [Ping timeout: 252 seconds]
sz0 has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter> <r00ster91> @bew unfornately i cant even come to build it. because when I build I get the error already. So i think i need to set the environment variable to something before i run.
<hightower2> When I have an Iterator and call to_set, it sets iterator's @current to last element and sets @reached_end=true. How can I rewind/reset it?
bonemind has quit [Quit: WeeChat 2.0.1]
bonemind has joined #crystal-lang
rohitpaulk has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
<RX14> hightower2: probably the rewind method on the iterator
<RX14> Not all iterators support it though
rohitpaulk has quit [Ping timeout: 248 seconds]
<RX14> Obviously if it's something coming from the network you can't simply rewind it
<RX14> If it's in memory you can
rohitpaulk has joined #crystal-lang
<hightower2> right, right, it comes from something like (10..20).step(2).to_set
<hightower2> (or rather, calling #to_set causes it to go to the end)
<FromGitter> <yxhuvud> Hmm, I wonder if there is a reason behind Enumerable#max(n : Int) (and the corresponding #max_by) not existing. It would be pretty slick for my current use case :/
<RX14> @yxhuvud well it would't really make sense on enumerable
<RX14> since taking the max n values would require a sorted array
<RX14> ...hmm
<RX14> maybe not
<FromGitter> <yxhuvud> well, it would require a sorted array of n entries.
<FromGitter> <yxhuvud> which is .. not costly.
<RX14> yeah
<RX14> yep it's just not been implemented
<RX14> you can PR it
<RX14> but if you do you should obviously do min and min_by and min_by(n) and max_by(n)
<RX14> for symmetry
<FromGitter> <yxhuvud> probably will when I get time. I guess it was a late addition to ruby stdlib :) (and of course, regarding the min-variants).
duane has quit [Ping timeout: 240 seconds]
rohitpaulk has quit [Ping timeout: 252 seconds]
wojnar has joined #crystal-lang
duane has joined #crystal-lang
bonemind has quit [Quit: WeeChat 2.0.1]
<hightower2> Hey folks I've just documented a lib I've created for expressing powerful date/time schedules, recurring events, etc. in Crystal. It's available at https://github.com/docelic/crystime
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
qard has joined #crystal-lang
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<watzon> Found a simple replacement for the Equalizer gem https://play.crystal-lang.org/#/r/3nl6
<watzon> Lol and it happens to be almost exactly what `def_equals` does, but while allowing you to pick the class of `other`
maattdd_ has quit [Ping timeout: 245 seconds]
<RX14> watzon, I guess the stdlib doesn't quite cover the case of defining equals with another class
<RX14> i'd personally just use def_hash_and_equals
<RX14> and then manually write == for other types
<RX14> depends how many other types you have i guess
<watzon> I don't really understand the `#hash` method
<RX14> it's just for Hashes
<RX14> when you out it in the hash it's required
<RX14> it's the hash table key
hugo__ has joined #crystal-lang
hugo__ has quit [Client Quit]
reich has joined #crystal-lang
<hightower2> philfine hey got any further with your channels/events code other than what RX14 posted to this channel the other day?
<RX14> I think we got to what @philfine wanted
<hightower2> Yes yes, I thought he maybe added something else
<hightower2> Basically, what I am trying to do is have an equivalent of Cute but which works slightly different. Specifically, I would define event names and their arguments (this is what Cute already does), but then just loosely speaking to be used such as: signal :my(a : Int32); add_listener(:my, someBlock); emit(:my, args) or signals[:my].emit(args)
<hightower2> Based on your example with objects I thought of a possible approach and came up with https://play.crystal-lang.org/#/r/3nll
<hightower2> This seems to work but any comments/improvements would be more than welcome
<hightower2> (I am thinking I would need macros to generate all this arguments-specific code, very similar to how 'signal' macro in Cute does it)
<hightower2> Actually what I pasted above doesn't work. It worked because I had a single type, and placed in the base class
<hightower2> So still searching for ideas
<hightower2> Need to keep staring into your example :)
<FromGitter> <genericpenguin> Hey guys. I'm trying to create a multidimensional array and I'm hitting what the compiler says is a bug. I'm trying this: ⏎ ⏎ ```@grid = Array.new(@size_x) { |i| [0] }``` [https://gitter.im/crystal-lang/crystal?at=5a95c85e888332ee3add7cac]
wojnar has quit [Remote host closed the connection]
<FromGitter> <genericpenguin> There's more layers but this simplified example fails.
<FromGitter> <genericpenguin> I've tried various Array constructors in place of the [0] but they all seem to trigger this issue.
<FromGitter> <genericpenguin> Here's a gist of the output: https://gist.github.com/genericpenguin/262ebb941d1db2ad31e3b89ceba5969d
<FromGitter> <genericpenguin> Crystal version is 0.24.1 (2018-01-27) and LLVM version is LLVM: 5.0.1
<FromGitter> <genericpenguin> oops nm. I found an existing issue - https://github.com/crystal-lang/crystal/issues/5666
<FromGitter> <genericpenguin> Sorry for the noise.
vivus has joined #crystal-lang
vivus has left #crystal-lang [#crystal-lang]
<FromGitter> <genericpenguin> It looks like it only happens when I use that constructor with the instance variable of my class
<FromGitter> <genericpenguin> Yep. If I do: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ It works. [https://gitter.im/crystal-lang/crystal?at=5a95cc21758c233504ca16eb]
alex`` has quit [Ping timeout: 256 seconds]
<oprypin> genericpenguin, please produce a minimal but complete example that causes the error
maattdd_ has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
reich has quit [Ping timeout: 248 seconds]
rohitpaulk has joined #crystal-lang
maattdd_ has quit [Ping timeout: 260 seconds]
duane has quit [Ping timeout: 248 seconds]
<oprypin> nvm, you said you found the issue
<FromGitter> <genericpenguin> @oprypin I thought that was it but their problem was an actual misuse error (passing type instead of size). I'm pretty sure I'm not making the same error. This reproduces the issue: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a95e2316fba1a703aac7d43]
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <genericpenguin> I think I'm just screwing up the type inference. I need to declare the array properly.
<FromGitter> <genericpenguin> Yep, that was it. I just needed to declare the array: ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5a95e48c888332ee3ade0fcb]
cimrie has joined #crystal-lang
cimrie has quit [Client Quit]