Rounin has quit [Ping timeout: 272 seconds]
smurfke_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Garb0 has quit [Quit: Garb0]
Garb0 has joined #ruby
Garb0 has quit [Quit: Garb0]
swaggboi has quit [Quit: C-x C-c]
swaggboi has joined #ruby
gr33n7007h has joined #ruby
gearnode has quit [Ping timeout: 264 seconds]
chonkbit has joined #ruby
lunarkitty has quit [Quit: Connection closed for inactivity]
<nakilon> > [*0..255].map(&:chr).join.encode "utf-8"
<nakilon> Encoding::UndefinedConversionError: "\x80" from ASCII-8BIT to UTF-8
<nakilon> what am I supposed to do to convert without an exception?
<nakilon> I expect the \x80 to be converted to 110 0000010 000000
<nakilon> i.e. U+0080
<nakilon> oh wait, ASCII table is 128 long...
<zodeishi> nakilon: String#force_encoding might do what you want.
<nakilon> hmmm, I have a feeling I didn't really understand what the force_encoding do
<nakilon> I though it doesn't edit the data
<nakilon> wait, it doesn't _<>
<havenwood> nakilon: Array.new(256) { |n| n.chr Encoding::UTF_8 }
<havenwood> >> Encoding::UTF_8
<ruby[bot]> havenwood: # => #<Encoding:UTF-8> (https://carc.in/#/r/ba3l)
<havenwood> >> Encoding::UTF_8.to_s
<ruby[bot]> havenwood: # => "UTF-8" (https://carc.in/#/r/ba3m)
<havenwood> nakilon: #chr takes encoding as an arg
<havenwood> nakilon: Prefer `Array.new` when starting at zero for fewest objects and method calls.
<nakilon> I'm not making arrays, that was just a random input data
<nakilon> so if there are two cases
<nakilon> Array.new(256) { |n| n.chr Encoding::UTF_8 }.join
<nakilon> [*0..255].map(&:chr).join.force_encoding("utf-8")
<nakilon> I wonder which one should I chose to convert the input 0..255 data to utf-8 to send to IRC as a bot repl output
lunarkitty has joined #ruby
<nakilon> I have a feeling that the latter isn't really valid
<nakilon> and is just waiting to throw exception somewhere
<havenwood> nakilon: [*0..255].pack('U*')
<havenwood> >> [*0..255].pack('U*') == Array.new(256) { |n| n.chr Encoding::UTF_8 }.join
<ruby[bot]> havenwood: # => true (https://carc.in/#/r/ba3n)
<nakilon> good
<nakilon> >> [0,10,13].pack('U*') == "\x00\x0a\x0d"
<ruby[bot]> nakilon: # => true (https://carc.in/#/r/ba3o)
<zodeishi> >> [0,10,13,0x80].pack('U*').each_byte.map{_1.to_s(2)}
<ruby[bot]> zodeishi: # => ["0", "1010", "1101", "11000010", "10000000"] (https://carc.in/#/r/ba3p)
<nakilon> hm, there is another problem
<nakilon> >> [*0..255].pack("U*").size
<ruby[bot]> nakilon: # => 256 (https://carc.in/#/r/ba3q)
<nakilon> >> [*0..255].pack("U*").bytes.pack("U*").size
<ruby[bot]> nakilon: # => 384 (https://carc.in/#/r/ba3r)
<nakilon> the problem is that I don't know if the input string is ascii or utf-8 already
<nakilon> I wonder if checking for .encoding is a clean way to do it
<nakilon> I'll probably have to believe in that
<havenwood> >> [*0..255].pack("U*").codepoints.pack("U*").size
<ruby[bot]> havenwood: # => 256 (https://carc.in/#/r/ba3s)
<nakilon> and ask the user to really convert the encoding before he sends be a string with encoding="ascii"
<nakilon> >> [*0..255].pack("U*").codepoints.pack("U*") == [*0..255].map(&:chr).join.codepoints.pack("U*")
<ruby[bot]> nakilon: # => true (https://carc.in/#/r/ba3t)
<nakilon> hm
<nakilon> so .codepoints.pack("U*") should be the safe way to go?
<havenwood> nakilon: As long as you're dealing with codepoints and no more complex grapheme clusters. I don't quite follow what you're doing.
<nakilon> havenwood sanitizing the irc bot output
<havenwood> >> (127462.chr(Encoding::UTF_8)..).take(26).repeated_permutation(2).map(&:join)
<ruby[bot]> havenwood: # => ["🇦🇦", "🇦🇧", "🇦🇨", "🇦🇩", "🇦🇪", "🇦🇫", "🇦🇬", "🇦🇭", "🇦🇮", "🇦🇯", "🇦🇰", "🇦🇱", "🇦🇲", "🇦🇳", "🇦🇴", "🇦🇵", "🇦🇶 ...check link for more (https://carc.in/#/r/ba3z)
zodeishi has quit [Ping timeout: 268 seconds]
<nakilon> >> " a a ".split(" ")
<ruby[bot]> nakilon: # => ["a", "a"] (https://carc.in/#/r/ba4e)
<nakilon> is there a stdlib way to get ["", "a", "", "a", ""] or should I reinvent the wheel?
krma has joined #ruby
krma has left #ruby [#ruby]
chonkbit has quit [Ping timeout: 244 seconds]
lfalcao has joined #ruby
<havenwood> >> " a a ".scan /\S|\B/
<ruby[bot]> havenwood: # => ["", "a", "", "a", ""] (https://carc.in/#/r/ba4l)
<havenwood> nakilon: Is that ^ what you mean?
<nakilon> havenwood need to split by arbitrary character
<havenwood> nakilon: Have a minimal reproduction case or test cases?
<nakilon> >> f = ->(a,b){ s,i,r=0,0,[]; until i==a.size do (r.push a[s...i] ; s=i+b.size) if i>=s && a[i,b.size]==b ; i+=1 end ; r+[a[s..-1]] } ; f["a aa a", "a"]
<ruby[bot]> nakilon: # => ["", " ", "", " ", ""] (https://carc.in/#/r/ba4m)
<havenwood> >> "a aa a".split 'a', -1
<ruby[bot]> havenwood: # => ["", " ", "", " ", ""] (https://carc.in/#/r/ba4n)
<nakilon> >> " a a ".split ' ', -1
<ruby[bot]> nakilon: # => ["a", "a", ""] (https://carc.in/#/r/ba4o)
<nakilon> >> f = ->(a,b){ s,i,r=0,0,[]; until i==a.size do (r.push a[s...i] ; s=i+b.size) if i>=s && a[i,b.size]==b ; i+=1 end ; r+[a[s..-1]] } ; f[" a a ", " "]
<ruby[bot]> nakilon: # => ["", "a", "", "a", ""] (https://carc.in/#/r/ba4p)
<havenwood> >> separator = ' '; " a a ".scan /[^#{separator}]|\B/
<ruby[bot]> havenwood: # => ["", "a", "", "a", ""] (https://carc.in/#/r/ba4q)
<havenwood> nakilon: Okay, I kinda follow what you're wanting now. Yeah, that's rather specific.
<nakilon> I won't call it specific
<nakilon> t's just plain trivial string split; the issue is that ruby's string#split includes unwanted exceptions
<nakilon> >> separator = ' '; "a a".scan /[^#{separator}]|\B/
<ruby[bot]> nakilon: # => ["a", "", "a"] (https://carc.in/#/r/ba4r)
<nakilon> >> separator = 'a'; " aa ".scan /[^#{separator}]|\B/
<ruby[bot]> nakilon: # => [" ", "", " ", ""] (https://carc.in/#/r/ba4s)
<nakilon> the only "untrivial" thing is when separator is "aa" and there is "aaa" substring but I'm pretty sure what I've implemented is the same as you would find in some C++ STL lib
<nakilon> just breaking the first match and +=sep.size
<nakilon> or even in C libs
<leftylink> very interesting
<leftylink> if split(' ') is the only problem, perhaps split(/ /) can be used instead
<nakilon> >> " a a ".split / /
<ruby[bot]> nakilon: # => (https://carc.in/#/r/ba4t)
<nakilon> >> " a a ".split(/ /)
<ruby[bot]> nakilon: # => ["", "a", "", "a"] (https://carc.in/#/r/ba4u)
lunarkitty has quit [Quit: Connection closed for inactivity]
lfalcao has quit [Ping timeout: 264 seconds]
konsolebox has joined #ruby
d0htem has quit [Quit: Connection closed for inactivity]
Bounga has joined #ruby
Bounga has quit [Remote host closed the connection]
gearnode has joined #ruby
arestifo has joined #ruby
seabre has quit [Ping timeout: 252 seconds]
seabre has joined #ruby
yxhuvud has joined #ruby
ollysmith has quit [Quit: ZNC 1.8.2+deb2+b1 - https://znc.in]
arestifo has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ollysmith has joined #ruby
gearnode has quit [Ping timeout: 268 seconds]
pwnd_sfw has quit [Quit: Ping timeout (120 seconds)]
pwnd_sfw has joined #ruby
arestifo has joined #ruby
lunarkitty has joined #ruby
Garb0 has joined #ruby
arestifo has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Rounin has joined #ruby
arestifo has joined #ruby
arestifo has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
gr33n7007h has quit [Quit: WeeChat 3.1]
gr33n7007h has joined #ruby
arestifo has joined #ruby
arestifo has quit [Client Quit]
jetchisel has joined #ruby
lunarkitty has quit [Quit: Connection closed for inactivity]
henninb has joined #ruby
Garb0 has quit [Quit: Garb0]
jetchisel has quit [Ping timeout: 244 seconds]
jetchisel has joined #ruby
smurfke_ has joined #ruby
zodeishi has joined #ruby
smurfke_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
smurfke_ has joined #ruby
smurfke_ has quit [Client Quit]
smurfke_ has joined #ruby
smurfke_ has quit [Ping timeout: 264 seconds]
Garb0 has joined #ruby
Garb00 has joined #ruby
konsolebox has quit [Read error: Connection reset by peer]
konsolebox has joined #ruby
Garb0 has quit [Ping timeout: 245 seconds]
Rounin has quit [Ping timeout: 264 seconds]
d0htem has joined #ruby
henninb has quit [Remote host closed the connection]
lfalcao has joined #ruby
lfalcao has quit [Ping timeout: 245 seconds]
Garb00 has quit [Ping timeout: 265 seconds]
arestifo has joined #ruby
arestifo has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Garb0 has joined #ruby
lfalcao has joined #ruby
Garb0 has quit [Ping timeout: 252 seconds]
Garb0 has joined #ruby
d0htem has quit [Quit: Connection closed for inactivity]
<havenwood> http https://bugs.ruby-lang.org/issues.json | jq -C | more -r
lfalcao has quit [Ping timeout: 264 seconds]
Garb0 has quit [Read error: Connection reset by peer]
Garb0 has joined #ruby
motherr has joined #ruby
motherr_ has quit [Ping timeout: 264 seconds]
motherr_ has joined #ruby
motherr has quit [Ping timeout: 264 seconds]
jidar has quit [Quit: too stupid]
Garb0 has quit [Read error: Connection reset by peer]
Garb0 has joined #ruby
Garb0 has quit [Read error: Connection reset by peer]
lfalcao has joined #ruby
lfalcao has quit [Ping timeout: 264 seconds]
Garb0 has joined #ruby
smurfke_ has joined #ruby
reset has joined #ruby
Garb0 has quit [Read error: Connection reset by peer]
Garb0 has joined #ruby
Garb0 has quit [Read error: Connection reset by peer]
Garb0 has joined #ruby
d0htem has joined #ruby
denny has joined #ruby
postmodern has joined #ruby
dostoyevsky2 has quit [Quit: leaving]
dostoyevsky2 has joined #ruby
<sweater2> My brain gave up on this. Can someone explain basically everything around here, namely:
<sweater2> What is `included`, or rather how does it work, what is `attr_reader`, what is this password=password @password password; super magic?
<sweater2> It _looks_ like a function that takes a password, attaches it as a member to a new closure and returns either an instance of the parent class or nil
<sweater2> So, kind of a very weird setter, but I'm fairly certain I'm fairly wrong. Halp.
gearnode has joined #ruby
<denny> sweater2: included is part of the ActiveSupport::Concern stuff iirc - for setting up mixins. It's just syntactic sugar, you can do the same stuff without it but I forget how.
<denny> sweater2: in this case ... that getter will be available in any class that includes this module
<denny> attr_reader creates a getter method, which will return the value of the same-named instance variable
<leftylink> ah too bad, I thought included was in Module, but it looks to me like it's a different included
<sweater2> denny: thanks
<sweater2> but what's `password` there then?
<sweater2> is it a setter?
<sweater2> how does it work.
<weaksauce> attr_reader is shorthand for creating a default getter and password= is the setter
<denny> then the password method is the setter for that same var
<weaksauce> attr_accessor does a setter and getter for you
<sweater2> weaksauce: is `password=` an identifier?
<denny> they've used a method for the setter rather tahn using attr_accessor so that they could add the call to super
<sweater2> or is it `password` -- the identifier, and `=` some modifier for it?
<weaksauce> and attr_writer is the one that creates a default setter for you that is password=
<denny> 'password=' is the method name
<sweater2> understood
<denny> so in the code when you write 'password = "foobar"', that method is called
<weaksauce> attr_writer :password is the same as def password=
<sweater2> ah
<weaksauce> but they don't use that because they want to do other things
<weaksauce> when writing to the attribute
smurfke_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<sweater2> weaksauce: I only see that they return super if super exists?..
<weaksauce> correct
<sweater2> which I can't wrap my head around. (I'm coming from Elixir / Haskell, so I haven't seen OOP in a while, especially that kind)
<leftylink> it's more important than returning it because it would call it
<sweater2> Like why wouldn't they just return current object
<denny> My personal take (coming from Perl, a much scorned language!) is that Ruby likes magic; if you're not familiar with the idioms then it can be a bit much sometimes.
<sweater2> (sorry for extremely stupid questions)
<denny> But once you're used to them it's obviously very neat and cool
<leftylink> When used without any arguments super uses the arguments given to the subclass method.
<sweater2> denny: my take is very similar: https://social.doma.dev/@jonn/106359935746539686
<sweater2> leftylink: tyty will read!
<denny> Also, fwiw, I would guess that Devise is a pretty hairy codebase, because it does some very complex integration stuff? That is a guess, but ... probably quite a hard bit of code to read through if you're not coming from a Ruby background in the first place.
<sweater2> denny: what I dislike the most is that there is more often than not, no way to understand where something was defined or slapped onto something else. Conversely, reading a module definition doesn't guarantee that you have the complete picture.
<sweater2> But these all are tradeoffs for convenience for people who know what they are doing (tm)
<sweater2> and where too look.
<sweater2> So I'm not too upset, taking it on the chin so far.
<denny> Rails explicitly has the 'motto' or whatever of 'convention over configuration' - basically, do it the same way as everybody else and it'll run smoothly. Try to do it a bit differently and, well, steering off of the Rails doesn't generally end well :)
<sweater2> denny: oh yes, it's OK, I am adding SSI to Mastodon, so there's no way around implementing Devise model + Warden strategy
<denny> (Meanwhile Perl has "there's more than one way to do it" - culture clash much!)
<denny> Cool. Good luck!
smurfke_ has joined #ruby
<weaksauce> yeah i'd think devise is a bit hairy too
<weaksauce> sweater2 there are some introspection methods too
<weaksauce> but not entirely reliable iirc
denny is now known as denny-_-
<weaksauce> i can't remember if it handles metaprogramming off the top of my head but source_location is one method you can use
<denny-_-> I've found just doing 'ls ClassIAmCurrentlyFighting' in a pry console is quite educational
<denny-_-> And often terrifying when you realise how much other stuff anything in Rails is attached to :D
<weaksauce> hah
<denny-_-> also my mind was blown by an interview candidate a year or two ago doing 'cd instance_of_object' and then 'ls' and then poking around in its instance variables
<denny-_-> pry is lots of fun, either Perl doesn't have anything similar or I just didn't get introduced to it
denny-_- is now known as denny--
<weaksauce> heh
<weaksauce> activesupport concern is just two methods
denny-- is now known as denny
<denny> I haven't quite got my head around the difference between included { def self.foo ... } and class_methods { def foo ... } in a module and defining them in a class and inheriting them from another class. No doubt there are fairly clear rules (I think some things append methods and others prefix them), but so far I just hit it with a stick until it seems to work.
<weaksauce> yeah i read the metaprogramming ruby book and the object hierarchy is odd and there is a lot of malleability and footguns
smurfke_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Rounin has joined #ruby
SuperLag has quit [Quit: reboot that VM dude]
SuperLag has joined #ruby
gearnode has quit [Ping timeout: 265 seconds]
Garb0 has quit [Ping timeout: 245 seconds]
Garb0 has joined #ruby