<FromGitter>
<watzon> I'd avoid using regex there if you could though, especially if it's user input. You could also attempt type conversions inside of a `begin/rescue` block.
<FromGitter>
<watzon> Pretty sure that would be more preformant
<FromGitter>
<watzon> Oh yeah, I forgot you could do that
<FromGitter>
<watzon> Case is pretty nice. Sometimes I wish it was a little better for pattern matching, but it is a lot more powerful than a lot of languages
<FromGitter>
<watzon> Ruby actually just added some new pattern matching functionality to case
ur5us has quit [Ping timeout: 260 seconds]
<FromGitter>
<randiaz95> Sorry to be ungrateful, but I wanted to note that any int also returns Decimal after testing
<FromGitter>
<randiaz95> so you must check for "." instance inside also
<FromGitter>
<randiaz95> need to put {value1, value1} though
<FromGitter>
<watzon> Oh interesting. I actually didn't know it could do that.
<FromGitter>
<randiaz95> sure, and use underscore if you aren't using 2 methods.
<FromGitter>
<watzon> Actually it kinda makes sense though, you're basically pattern matching on a tuple.
<FromGitter>
<randiaz95> like: `when {.even?, _}
<FromGitter>
<watzon> Yeah the underscore can be used in blocks and such too
<FromGitter>
<watzon> Saves you from having to define a variable you're never going to use
<FromGitter>
<randiaz95> yep, *Coming from go lol I know I should not have variables I won't use
<FromGitter>
<randiaz95> hey @watzon
<FromGitter>
<watzon> Yeah?
<FromGitter>
<randiaz95> Is there any way to do Array.each do |x| end but instead of just getting the element x, also get the index
<FromGitter>
<randiaz95> essentially a parallel to for index, value in enumerate(array) in python
<FromGitter>
<watzon> `each_with_index`?
<FromGitter>
<watzon> There's also `map_with_index`
<FromGitter>
<randiaz95> right, so when I looked at the api for each_with_index, its parameters are the indexes itself
<FromGitter>
<randiaz95> not to run through entire array
<FromGitter>
<randiaz95> nvm
<FromGitter>
<randiaz95> I probably confused it with another method
<FromGitter>
<watzon> I'm confused. With `each_with_index` it's basically the same as `each`, but it also supplies the index as a second property.
<FromGitter>
<randiaz95> yep,
<FromGitter>
<randiaz95> I saw each_index first... not each with index
<FromGitter>
<watzon> Ahhh ok haha
<FromGitter>
<watzon> Yeah `each_with_index` should be exactly what you want
<FromGitter>
<randiaz95> Lol, god bless me
ur5us has joined #crystal-lang
<FromGitter>
<stnluu_twitter> > has anyone ever written a macro, that wraps around a block of other macros? like: ⏎ > ``` ⏎ > my_big_macro param1, param2, do ⏎ > sub_macro p1, p2 ⏎ > sub_macro p3, p4 ... [https://gitter.im/crystal-lang/crystal?at=5e09954207a1a67d1d805552]
<FromGitter>
<watzon> Are you having an issue making it work?
<FromGitter>
<stnluu_twitter> i dont have a lot of experience with macros, so just not sure how/what i can do to support that
<FromGitter>
<stnluu_twitter> i guess a more specific question is, can i call "yield" from within a macro to "paste" those sub macros in?
<FromGitter>
<stnluu_twitter> doesn't look like i can
<FromGitter>
<grkek> Just try not to mix it with anything else
<FromGitter>
<Nicolab> Hello, ⏎ ⏎ If anyone want to do a little bit of mentoring on Exercism (https://exercism.io/my/tracks/crystal). We are two waiting in the queue
<FromGitter>
<grkek> @Nicolab what do we have to do again ?
<FromGitter>
<Nicolab> The principle is to correct the steps. Quickly don't consume too much time
<FromGitter>
<Nicolab> The first exercises are simple when you know Crystal, it helps people who discover a language (Crystal in this case)
<FromGitter>
<j8r> he has certainly already received a notification
<FromGitter>
<j8r> wait at least a few days
<FromGitter>
<grkek> no problem just wanted to make sure :)
ht_ has quit [Remote host closed the connection]
ht_ has joined #crystal-lang
Nicolab has quit [Quit: Leaving.]
Human_G33k has joined #crystal-lang
HumanG33k has quit [Ping timeout: 260 seconds]
<FromGitter>
<Blacksmoke16> you'll need to wait the 30 days ^
Nicolab has joined #crystal-lang
<FromGitter>
<straight-shoota> > There is a practice mode (without mentor). I will correct myself by looking at other people's solutions :) ⏎ ⏎ This can certainly help, but you need to be careful with that. I noticed that a lot of published solutions are far from ideal. So you might just happen to learn something that's not worth learning it.
<FromGitter>
<straight-shoota> Unfortunately, having many stars is not an indicator for a quality solution either. For example: From the top rated solutions for the hello world exercise, only two define the method in a module.
hightower4 has joined #crystal-lang
<FromGitter>
<straight-shoota> @marynowac Instead of `zip.add`, just to `File.open("file1") { |file| IO.copy(file, zip) }`
<FromGitter>
<j8r> @straight-shoota maybe, but if (s)he looks at enough solutions, it will likely be good for learning, because we will naturally compare them
<FromGitter>
<j8r> And thinking which options are better, and why
<FromGitter>
<straight-shoota> Of course. For that very reason I do not advise against looking at other solutions. But you should do that with care and open eyes.
<FromGitter>
<straight-shoota> Also, as per my previous comment, it seems to be very often that many solutions have similar issues. Even top rated ones. Or maybe especially top rated ones?
<FromGitter>
<j8r> perhaps that's often the same set of people?
<FromGitter>
<j8r> (I don't know)
<FromGitter>
<bew> @straight-shoota did you do the exercism React ?
dwdv has quit [Ping timeout: 240 seconds]
ht_ has quit [Remote host closed the connection]
ht_ has joined #crystal-lang
<FromGitter>
<marynowac> @straight-shoota `File.open("file1") { |file| IO.copy(file, zip) }` returns ⏎ Error: private method 'write' called for Zip::Writer @marynowac ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e0a13bcd31dba03fdccfd3f]
<FromGitter>
<Nicolab> @straight-shoota Ok thanks. I try to compare and see the differences of the solutions (by looking, docs etc). Not perfect but I will keep my eyes open :)
<FromGitter>
<Nicolab> by the way, thank you @bew for your review
<FromGitter>
<bew> (;
ht_ has quit [Remote host closed the connection]
ht_ has joined #crystal-lang
<FromGitter>
<randiaz95> Guys... Radio waves don't get deflected, Gamma waves don't get deflected but light waves, which are in the middle of the spectrum do get deflected....
<FromGitter>
<randiaz95> Life is wild..
<FromGitter>
<randiaz95> If it wasn't for this fact, we wouldn't have non-radioactive wifi lol
dwdv has joined #crystal-lang
<Yxhuvud>
Eh, ever heard of RADAR? Radio waves definitely get reflected.
<Yxhuvud>
And if you ever has been to the dentist you have been subject to the reflections of high energy rays too.
<FromGitter>
<randiaz95> Well, we don't necessarily use radio, but a middle ground between radio and microwaves
<FromGitter>
<randiaz95> and sure, it gets deflected after 3rd floor lol
<FromGitter>
<straight-shoota> @marynowac Not sure what you mean
<FromGitter>
<straight-shoota> What do you want to achieve?
gangstacat has quit [Quit: Ĝis!]
gangstacat has joined #crystal-lang
Nicolab has quit [Ping timeout: 260 seconds]
Nicolab has joined #crystal-lang
Human_G33k has quit [Ping timeout: 260 seconds]
<FromGitter>
<marynowac> i got huge set of large files (600 mb - 5 gb) and that files are already compressed. i have to create zip archives contain 4-10 files each. so i don't want to waste time for another compression and just store files inside archive.
<FromGitter>
<marynowac> doc says: NOTE only compression methods 0 (STORED) and 8 (DEFLATED) are supported. so i wanna use method 0, but don't know how to set it.
<FromGitter>
<marynowac> but if PR are welcomed i'm able to create PR and fix a typo in the error message: mistmacth :))
<FromGitter>
<wontruefree> I just wanted to let people know we are hosing a meetup on the state of AI in Crystal this Thursday chicagocrystal.org/events/clzwlrybccbdb/
<FromGitter>
<wontruefree> hahaha
<FromGitter>
<wontruefree> I love Chicago
<FromGitter>
<wontruefree> also you can remote in
<FromGitter>
<wontruefree> we make it as remote friendly as we can
<FromGitter>
<wontruefree> the speaker is also remote
<FromGitter>
<wontruefree> If you are interested in how the night goes here is our last meetup https://youtu.be/5rpZOtcCHtk
<FromGitter>
<randiaz95> :o
<FromGitter>
<randiaz95> Im so lonely here in Miami
<FromGitter>
<wontruefree> thank you @asterite again for you talk it was really cool
<FromGitter>
<randiaz95> no one codes lol
<FromGitter>
<wontruefree> hahaha
<FromGitter>
<wontruefree> Well if you are ever in Chicago let me know
<FromGitter>
<wontruefree> so do you mostly do remote work?
<FromGitter>
<Blacksmoke16> @marynowac welp, yea sorry im out of ideas
HumanG33k has joined #crystal-lang
<FromGitter>
<r00ster91> Hello. When should I use `same_thread: true` for a `spawn`? Should I use it for rather small and less important things that should better not take up a new thread?
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
Nicolab has joined #crystal-lang
<FromGitter>
<grkek> @Blacksmoke16 I think I finally implemented the threading properly and bumped the rps from 30k to 56959
<FromGitter>
<Blacksmoke16> oh?
<FromGitter>
<grkek> on a single instance
<FromGitter>
<grkek> 1142131 requests in 20.05s
<FromGitter>
<Blacksmoke16> nice one, what all did you have to do?
<FromGitter>
<grkek> spawn do
<FromGitter>
<grkek> end
<FromGitter>
<grkek> :D
<FromGitter>
<grkek> that's it
<FromGitter>
<Blacksmoke16> :thinking:
<FromGitter>
<Blacksmoke16> where did you put that?
<FromGitter>
<grkek> it is implemented pretty stupidly but it works ?
<FromGitter>
<grkek> also If I run another instance of the same application it doesn't bump up the rps
<FromGitter>
<grkek> do you know the cause of it ?
<FromGitter>
<Blacksmoke16> i dont fully understand how this helped in the first place?
<FromGitter>
<Blacksmoke16> each request is executed in a fiber already (assuming you're using `HTTP::Server`)
<FromGitter>
<Blacksmoke16> so even if the handler was taking a while it would already switch to another request while waiting for this one to be processed
<FromGitter>
<halfdan> FWIW I don't expect this to work - I've yet to look at the signature of Hash in Crystal, it's just the error that confuses me
<FromGitter>
<halfdan> Seems to work with `->(hash : Hash(String, Int32), key : String) { hash[key] = key.size }`
yukai has joined #crystal-lang
<FromGitter>
<randiaz95> Hi guys!!!
<FromGitter>
<randiaz95> Is there any way to use the .select! method on an array without modifying self?
<FromGitter>
<halfdan> Use select without the bang
<FromGitter>
<randiaz95> Bang bang
<FromGitter>
<randiaz95> Thank you!!!
<FromGitter>
<randiaz95> it worked.
<FromGitter>
<halfdan> This follows Ruby's pattern. Bang methods modify self, without they return a copy
<FromGitter>
<randiaz95> Wow, that is perfect information lol I wanted to learn more about ! ? in crystal and ruby
<FromGitter>
<randiaz95> I come from Java/Python origins
<FromGitter>
<randiaz95> That is great syntax though man now that I know how to use it.
<FromGitter>
<randiaz95> kind of like a shotgun though. If you don't know how to use it; you can do some nasty bugs lol...
<FromGitter>
<halfdan> methods ending with a question mark (in Ruby) usually return a boolean or can be evaluated to a boolean
<FromGitter>
<randiaz95> Right, I know that about ruby. It doesn't necessarily apply in Crystal though; it may or may not be true.
Nicolab has joined #crystal-lang
<FromGitter>
<Daniel-Worrall> It is true for the stdlib and anyone correctly writing crystal shards. A method with a question mark suffix should only return a boolean.