ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
HumanG33k has quit [Ping timeout: 260 seconds]
HumanG33k has joined #crystal-lang
<FromGitter> <djberg96> I seem to have frozen my repl with: `Range.new(" ", "~").to_a`
ur5us has quit [Ping timeout: 252 seconds]
<FromGitter> <Blacksmoke16> Probably lot of chars between those
Sankalp- has joined #crystal-lang
Sankalp has quit [Ping timeout: 264 seconds]
Sankalp- is now known as Sankalp
renich has quit [Quit: Leaving]
irc_user has joined #crystal-lang
jmdaemon has quit [Ping timeout: 264 seconds]
<FromGitter> <djberg96> should just be 32..126
<FromGitter> <djberg96> `("A".."z").to_a` - same
<FromGitter> <Blacksmoke16> In the interpreter?
<FromGitter> <Blacksmoke16> oh, try doing `('A'..'z').to_a`
<FromGitter> <Blacksmoke16> i.e. `Char` type not `String`
<FromGitter> <Blacksmoke16> seems the string one just isnt performant once you get to special chars
<FromGitter> <djberg96> aha, thanks!
<FromGitter> <djberg96> Is there a crystal equivalent of Ruby's `Enumerable#grep`?
<FromGitter> <Blacksmoke16> is that any diff than `#find`?
<FromGitter> <djberg96> find only finds the first element, doesn't it?
<FromGitter> <Blacksmoke16> okay, `#select` then :P
<FromGitter> <djberg96> yep, that should work, thanks!
<FromGitter> <Blacksmoke16> there's also an overload that accepts a value which does the `===` comparison. super helpful for extracting elements of a specific type or what have you
<FromGitter> <djberg96> fantastic
taupiqueur has joined #crystal-lang
irc_user has quit [Quit: Connection closed for inactivity]
<rocx> speaking of ruby methods missing, i did notice integers didn't have a `#between?` method. though that could just simply be `(x..y).includes? z`
<FromGitter> <Blacksmoke16> or prob `x <= z <= y`?
wwalker has quit [Quit: leaving]
wwalker has joined #crystal-lang
<FromGitter> <moe:busyloop.net> not a good method to have imho. have to look at the docs to find out if it's inclusive or exclusive.
irc_user has joined #crystal-lang
<FromGitter> <djberg96> does crystal have the equivalent of `:undef => :replace` for string encoding?
<FromGitter> <Blacksmoke16> hm?
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/1.6.2/String.html#scrub(replacement=Char::REPLACEMENT):String-instance-method ?
<FromGitter> <djberg96> ok, will try that, thanks
<FromGitter> <djberg96> https://ruby-doc.org/core-2.7.2/String.html#method-i-encode in case you're wondering what I'm talking about
<FromGitter> <Blacksmoke16> oh so more like https://crystal-lang.org/api/master/String.html#encode%28encoding%3AString%2Cinvalid%3ASymbol%7CNil%3Dnil%29%3ABytes-instance-method then
jmdaemon has joined #crystal-lang
ur5us has joined #crystal-lang
jmiven has quit [Quit: reboot]
jmiven has joined #crystal-lang
Sankalp has quit [Ping timeout: 252 seconds]
_ht has joined #crystal-lang
Sankalp has joined #crystal-lang
_ht has quit [Remote host closed the connection]
<FromGitter> <djberg96> well, in this case I need to keep the original character count
<FromGitter> <Blacksmoke16> what are you wanting to do?
<FromGitter> <djberg96> there a way to force encode it to US-ASCII?
<FromGitter> <djberg96> short version is I'm trying to port this snippet over to Crystal: https://github.com/djberg96/ptools/blob/main/lib/ptools.rb#L75-L85
<FromGitter> <djberg96> I was going to just simulate the `:replace` with `s.bytes.to_a.fill(63, 128..255)` but that gives me an IndexError
<FromGitter> <djberg96> korean text, in this case the bytes are `[237, 149, 156, 234, 181, 173, 236, 150, 180, 236, 157, 152, 32, 235, 130, 180, 236, 154, 169, 235, 182, 132, 236, 132, 157, 236, 157, 132, 32, 236, 156, 132, 237, 149, 156, 10]`
<FromGitter> <djberg96> the idea is that we don't want to accidentally consider that text a binary
<FromGitter> <Blacksmoke16> you can use that encode method to get the bytes of the string in a particular encoding yea
<FromGitter> <Blacksmoke16> tho i dont really follow what this method is doing
<FromGitter> <djberg96> basically it's checking to see if 30 percent or more of the bytes are non-textual
<FromGitter> <Blacksmoke16> oh, by replacing the textual ones with `nil` or something?
<FromGitter> <djberg96> Ruby replaces it with "?"
<FromGitter> <djberg96> or “uFFFD” depending
<FromGitter> <Blacksmoke16> thats essentially what `#scrub` does
<FromGitter> <Blacksmoke16> but you can change the char to be `?` if you wanted
<FromGitter> <djberg96> scrub only works if the bytes are invalid UTF-8
<FromGitter> <Blacksmoke16> ah okay, yea then `str.encode "US-ASCII", :skip` then compare the size from before/after?
<FromGitter> <djberg96> guess i could do that :)
<FromGitter> <djberg96> I need an overloaded version of scrub that let's me set the encoding to check against :)
<FromGitter> <Blacksmoke16> idk how Ruby does it, but all strings in Crystal are UTF-8, so thats prob the reasoning for that
<FromGitter> <Blacksmoke16> can work with other encodings via bytes, but not as strings themselves
<FromGitter> <djberg96> why doesn't this work? `[237, 149, 63, 63, 181, 173, 236, 150, 180, 236, 157, 152, 32, 235, 130, 180, 236, 154, 169, 235, 182, 132, 236, 132, 157, 236, 157, 132, 32, 236, 156, 132, 237, 149, 156, 10].fill(63, 128..255)`
<FromGitter> <djberg96> idea here was to replace anything 128+ with 63 ("?").
<FromGitter> <Blacksmoke16> im not sure `#fill` is what you want?
<FromGitter> <Blacksmoke16> you prob want `#map!`?
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/1.6.2/Slice.html#map%21%28%26%3AT-%3E_%29%3Aself-instance-method
<FromGitter> <djberg96> ok, will do that, thanks
hightower2 has joined #crystal-lang
hightower2 has quit [Remote host closed the connection]
hightower2 has joined #crystal-lang
Starfoxxes has quit [Ping timeout: 248 seconds]