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
<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>
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
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`
<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…]
<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>
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.
<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.