havenwood changed the topic of #ruby to: Rules: https://ruby-community.com | Ruby 2.7.2, 2.6.6, 3.0.0-preview1: https://www.ruby-lang.org | Paste 4+ lines of text to https://dpaste.org | Books: https://goo.gl/wpGhoQ | Logs: https://irclog.whitequark.org/ruby | BLM <3 | Can't talk? Register/identify with NickServ
SeepingN_ has joined #ruby
SeepingN has quit [Disconnected by services]
ur5us_ has quit [Ping timeout: 264 seconds]
cloud69 has joined #ruby
<cloud69> I'm trying to pick a random string from an array but get: `NoMethodError: undefined method 'strip' for #<Array:0x000000afec634808>`: https://pastebin.com/Ds3xXX5Y anybody know?
<leftylink> there's a big difference between .sample and .sample(1). try them out and see
stryek has quit [Quit: Connection closed for inactivity]
<havenwood> cloud69: With the current level of human-like behavior they'll likely see through your ruse, for what it's worth. Is this really a purely academic exercise?
<havenwood> This bot seems like a bot.
<cloud69> Purely yeah!
<cloud69> Hehe I figured it'd set off some alarm bells ;)
<havenwood> cloud69: You've already required pry, so just jump in to a `binding.pry` on the line before the #sample and try it in the REPL.
ur5us_ has joined #ruby
<cloud69> Hey at least I'm not asking how to simulate clicks mouse movements right? :)
<havenwood> cloud69: The REPL is a lovely way to quickly sanity check values and try hunches.
<cloud69> havenwood: Great, I'm on it thanks!
tcrypt has quit [Quit: _ノ乙(、ン、)_]
Azure|dc has quit [Read error: Connection reset by peer]
<cloud69> ruby is so pretty i often find myself just staring at its beauty for hours and hours on end :D
<cloud69> * at it for hours
Azure has joined #ruby
bmurt has joined #ruby
bmurt has quit [Ping timeout: 265 seconds]
bmurt has joined #ruby
dhollinger has quit [Ping timeout: 264 seconds]
dhollinger has joined #ruby
Axy has joined #ruby
Axy has joined #ruby
Mia has quit [Ping timeout: 256 seconds]
orbyt_ has joined #ruby
Mia has joined #ruby
Mia has joined #ruby
Axy has quit [Ping timeout: 246 seconds]
duderonomy has quit [Quit: Textual IRC Client: www.textualapp.com]
bambanx has quit [Quit: Leaving]
ChmEarl has quit [Quit: Leaving]
johnny56 has quit [Ping timeout: 240 seconds]
<cloud69> havenwood: well random_browser is all good in pry so..
<cloud69> leftylink :D
<havenwood> &>> [].respond_to? :strip
<havenwood> cloud69: ^
<rubydoc> # => false (https://carc.in/#/r/9yc9)
<havenwood> &>> [1, 2, 3].sample(1)
<rubydoc> # => [1] (https://carc.in/#/r/9yca)
queip has quit [Ping timeout: 246 seconds]
<havenwood> &>> [1, 2, 3].sample(1).class
<rubydoc> # => Array (https://carc.in/#/r/9ycb)
<havenwood> &>> [1, 2, 3].sample.class
<rubydoc> # => Integer (https://carc.in/#/r/9ycc)
<havenwood> cloud69: Look at the arguments to your method and study which part the error says is wrong.
<havenwood> cloud69: What class do you expect to be stripping?
<havenwood> cloud69: And what class is it?
<cloud69> i'm not sure i'm stripping anything, i just wanted to pass a random browser string to `html = open(startpage, "User-Agent" => random_browser)`
<havenwood> cloud69: What class is `random_browser`?
<havenwood> cloud69: Doesn't it seem wrong?
<havenwood> cloud69: Look at what's expected versus what you're passing.
<havenwood> cloud69: What is the expected class of the value corresponding to the "User-Agent" string?
moldorcoder7 has quit [Quit: %bye mirc%]
<havenwood> cloud69: leftylink pointed to the cause of your problem. Did you try the difference in `pry`?
moldorcoder7 has joined #ruby
<havenwood> cloud69: From the command line, just type `pry` and try sampling with `1` as the argument versus no argument.
<cloud69> that i tried but both returned the useragent string. but i see you just ran some stuff to show one is an array and the other an integer
<cloud69> 2 sec
lucasb has quit [Quit: Connection closed for inactivity]
<cloud69> there we go, thanks guys :D
ur5us_ has quit [Ping timeout: 260 seconds]
impermanence has quit [Quit: Connection closed]
TCZ is now known as Tunuka
bamdad_ has joined #ruby
bamdad has quit [Ping timeout: 240 seconds]
bamdad_ has quit [Remote host closed the connection]
kristian_on_linu has quit [Remote host closed the connection]
<leftylink> hmm. you know why I don't like alias? its args are the opposite of ln -s
ur5us_ has joined #ruby
<leftylink> you know how to resolve this problem... just allow alias to accept its args in either order
<leftylink> chaos
Tunuka has quit [Quit: Things Take Time]
chouhoulis has quit [Remote host closed the connection]
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ur5us_ has quit [Ping timeout: 260 seconds]
Rudd0 has joined #ruby
howdoi has quit [Quit: Connection closed for inactivity]
bmurt has joined #ruby
bmurt has quit [Client Quit]
jmcgnh has quit [Ping timeout: 246 seconds]
cd has quit [Quit: cd]
adu has joined #ruby
jmcgnh has joined #ruby
SeepingN_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
queip has joined #ruby
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
baojg has quit [Remote host closed the connection]
baojg has joined #ruby
m27frogy has quit [Ping timeout: 260 seconds]
howdoi has joined #ruby
adu has quit [Quit: adu]
bocaneri has joined #ruby
akem_ has quit [Ping timeout: 258 seconds]
Emmanuel_Chanel has quit [Quit: Leaving]
bocaneri has quit [Max SendQ exceeded]
bocaneri has joined #ruby
bocaneri has quit [Max SendQ exceeded]
bocaneri has joined #ruby
Emmanuel_Chanel has joined #ruby
Emmanuel_Chanel has quit [Client Quit]
_whitelogger has joined #ruby
Emmanuel_Chanel has joined #ruby
nakilon has quit [Quit: Ping timeout (120 seconds)]
nakilon has joined #ruby
BenDover has joined #ruby
cthulchu_ has quit [Ping timeout: 258 seconds]
akem has joined #ruby
vondruch has joined #ruby
burgestrand has joined #ruby
m27frogy has joined #ruby
pabs has quit [Ping timeout: 265 seconds]
postmodern has joined #ruby
pabs has joined #ruby
ua has quit [Ping timeout: 256 seconds]
TomyWork has joined #ruby
Glumetu has joined #ruby
Hol_La has joined #ruby
ua has joined #ruby
Glumetu has quit [Ping timeout: 260 seconds]
Hol_La is now known as Glumetu
Hol_La has joined #ruby
Glumetu has quit [Ping timeout: 256 seconds]
Hol_La is now known as Glumetu
hiroaki has quit [Ping timeout: 260 seconds]
priodev has quit [Ping timeout: 268 seconds]
priodev has joined #ruby
braincrash has joined #ruby
fippy has quit [Quit: Leaving]
dionysus69 has joined #ruby
dionysus69 has quit [Remote host closed the connection]
dionysus69 has joined #ruby
duderonomy has joined #ruby
dionysus69 has quit [Remote host closed the connection]
dionysus69 has joined #ruby
johnny56 has joined #ruby
dionysus69 has quit [Remote host closed the connection]
dionysus69 has joined #ruby
dfucci has joined #ruby
dfucci has quit [Client Quit]
dfucci has joined #ruby
dionysus69 has quit [Remote host closed the connection]
baojg has quit [Remote host closed the connection]
baojg has joined #ruby
akem has quit [Ping timeout: 260 seconds]
mtsd has joined #ruby
BenDover has quit [Quit: BenDover]
vondruch has quit [Quit: vondruch]
vondruch has joined #ruby
impermanence has joined #ruby
cloud69 has quit [Quit: Connection closed for inactivity]
BenDover has joined #ruby
mtsd has quit [Quit: Leaving]
howdoi has quit [Quit: Connection closed for inactivity]
Jonopoly has joined #ruby
pinkpandabot has joined #ruby
burgestrand has quit [Quit: burgestrand]
Glumetu has quit [Ping timeout: 260 seconds]
Glumetu has joined #ruby
pinkpandabot has quit [Quit: use it or lose it principle]
baojg has quit [Remote host closed the connection]
cloud69 has joined #ruby
baojg has joined #ruby
TCZ has joined #ruby
Jonopoly has quit [Quit: WeeChat 2.9]
braincrash has quit [Ping timeout: 246 seconds]
mcr has quit [Ping timeout: 260 seconds]
mcr has joined #ruby
mkaito- has left #ruby ["WeeChat 2.9-dev"]
al2o3-cr has quit [Quit: WeeChat 2.9]
burgestrand has joined #ruby
malikith has joined #ruby
foxxx0 has quit [Quit: foxxx0]
pinkpandabot has joined #ruby
foxxx0 has joined #ruby
ujjain has joined #ruby
ujjain has quit [Changing host]
ujjain has joined #ruby
al2o3-cr has joined #ruby
burgestrand has quit [Quit: burgestrand]
vondruch has quit [Ping timeout: 240 seconds]
chouhoulis has joined #ruby
bmurt has joined #ruby
chouhoulis has quit [Ping timeout: 260 seconds]
<adam12> lol
hiroaki has joined #ruby
DaRock has quit [Ping timeout: 240 seconds]
Jonopoly has joined #ruby
baojg has quit [Remote host closed the connection]
vondruch has joined #ruby
baojg has joined #ruby
eoli3n has joined #ruby
<eoli3n> Hi
<eoli3n> in a vagrantfile, i want to increment a letter, something like this : http://ix.io/2E11
<eoli3n> but vagrant fails with errors : http://ix.io/2E13
<adam12> eoli3n: Looks like a vagrant-libvirt bug, not a Ruby bug.
<adam12> eoli3n: Oh actually
<adam12> eoli3n: You have LETTERS in the 3rd line
<adam12> eoli3n: but your variable is LETTER. Also, it shouldn't be all caps.
<eoli3n> yes i saw that but it was fixed here
<eoli3n> i mean i pasted wrong code
<adam12> eoli3n: Ok. Repaste current code and current error.
<eoli3n> ok
<adam12> eoli3n: I still think this is a vagrant-libvirt bug tho.
<eoli3n> that code gives errors i pasted up : http://ix.io/2E17
cd has joined #ruby
<eoli3n> but vagrant shouldn't "see" ruby part, so i don't get why you say that it is a vagrant bug
<eoli3n> if i set manually disks names it should work : lets try
<eoli3n> (without the loop)
<eoli3n> oh, you're right
<eoli3n> so my ruby is ok ? good news
<adam12> eoli3n: It's alomst fine. I'd personally assign LETTER to letter.
<adam12> eoli3n: LETTER is a constant, and technically constants dont' change.
<eoli3n> ah, right, fixed
<adam12> eoli3n: And you could do `DISK_COUNT.times do`
<adam12> eoli3n: Other than that, it's fine.
<eoli3n> lets try the times part
<adam12> eoli3n: Won't make a different since it's the same code.
<adam12> "same" as functionality.
<adam12> Just reads nicer / more intent revealing.
<eoli3n> oh strange... LETTER to letter fixed my first problem
chouhoulis has joined #ruby
<eoli3n> oh that's strange, i don't get what happened
<eoli3n> because the letter part is still commented
ChmEarl has joined #ruby
queip has quit [Excess Flood]
<eoli3n> adam12 times is not ok because it start to 0 and not 1
<leftylink> whiel that may be true, notice that (0..DISK_COUNT).size == DISK_COUNT + 1, therefore the original code creates one more disk than DISK_COUNT should suggest it should
<leftylink> &>> (0..DISK_COUNT).size
<eoli3n> yes i saw it
<rubydoc> stderr: -e:4:in `<main>': uninitialized constant DISK_COUNT (NameError)... check link for more (https://carc.in/#/r/9ydq)
<eoli3n> thanks
<leftylink> &>> (0..5).size
<rubydoc> # => 6 (https://carc.in/#/r/9ydr)
<eoli3n> the complete file : http://ix.io/2E1c
<leftylink> so it looks like DISK_COUNT's name should actually change to DISK_COUNT_MINUS_1
queip has joined #ruby
<eoli3n> leftylink i fixed it
<eoli3n> oups and i forget a LETTER to letter
<eoli3n> everything works now : http://ix.io/2E1d
<eoli3n> thanks
<eoli3n> LETTER to letter did the trick
<al2o3-cr> &>> disk_count = 4; disk_count.times.map.with_index(97) { "sd" << _2 }
<rubydoc> # => ["sda", "sdb", "sdc", "sdd"] (https://carc.in/#/r/9yds)
<al2o3-cr> :P
burgestrand has joined #ruby
<leftylink> &>> (?a..).take(4)
<rubydoc> # => ["a", "b", "c", "d"] (https://carc.in/#/r/9ydt)
<leftylink> I suggest
<al2o3-cr> nice :)
<adam12> &>> Enumerator.produce("sda", &:succ).take(4)
<rubydoc> # => ["sda", "sdb", "sdc", "sdd"] (https://carc.in/#/r/9ydu)
<leftylink> o we have reached peak ruby
<leftylink> thsi is excellent
<leftylink> oh, the enumerator produce isn't even necessary
<leftylink> range is fine
<adam12> Oh you're right.
<adam12> &>> ("sda"..).take(4)
<rubydoc> # => ["sda", "sdb", "sdc", "sdd"] (https://carc.in/#/r/9ydy)
<adam12> We're living in the future, friends.
malikith has left #ruby ["WeeChat 2.3"]
<al2o3-cr> :)
<al2o3-cr> and i'm very happy with that!
<eoli3n> :)
<eoli3n> never been there but #ruby is a fun place, i stay
burgestrand has quit [Quit: burgestrand]
lucasb has joined #ruby
<adam12> Heh
SeepingN has joined #ruby
cloud69 has quit [Quit: Connection closed for inactivity]
iNs_ has quit [Remote host closed the connection]
iNs has joined #ruby
TCZ has quit [Quit: Things Take Time]
code_zombie has joined #ruby
stryek has joined #ruby
svilenv has joined #ruby
<jidar> can somebody explain what &:succ is doing in the above Enumerator/
orbyt_ has joined #ruby
<adam12> jidar: &:succ is calling Symbol#to_proc, which returns a Proc. The second argument to Enumerator.produce is a block to be called for each iteration, where in this case we pass a proc. Behind the scenes, it's yielding the return object from the previous loop (let's call it current_value). So basically each time #each is called, it calls the proc with current_value, then re-assigns it.
akem has joined #ruby
Jonopoly has quit [Quit: WeeChat 2.9]
<adam12> &>> succ = :succ.to_proc; Enumerator.produce("sda") { |current_value| succ.call(current_value) }.take(4)
<rubydoc> # => ["sda", "sdb", "sdc", "sdd"] (https://carc.in/#/r/9ye0)
<adam12> I'm probably butchering the functionality of `each` slightly because I'd had to lookup the exact implementation.
sparr has quit [Changing host]
sparr has joined #ruby
TCZ has joined #ruby
Glumetu has quit [Quit: Glumetu]
baojg has quit [Remote host closed the connection]
baojg has joined #ruby
cthulchu_ has joined #ruby
eoli3n has quit [Remote host closed the connection]
dnadev2 has joined #ruby
<dnadev2> hi! question about using map for counting different groupings in a result: https://dpaste.org/v3kU
<adam12> dnadev2: Do you care if thing_1 thing_2 and thing_3 are separate variables?
<adam12> dnadev2: And any chance that i.thing.style returns something else outside of the 3 values?
<dnadev2> adam12, 1. no as long as i can tell the counts of each they don't have to be separate vars; 2. no, it's a fixed set of "things"
<adam12> dnadev2: @results.each_with_object(Hash.new { |hash, key| hash[key] = 0 }) { |obj, memo| memo[obj.thing.style] += 1 }
<adam12> dnadev2: I didn't test it but it looks accurate.
burgestrand has joined #ruby
burgestrand has quit [Client Quit]
<adam12> dnadev2: Might be more efficient to count this on the database tho, but you'd have to benchmark it.
<dnadev2> adam12, interesting and definitely prettier than mine.. gonna test, thanks. yea, true about the performance :/
vondruch has quit [Read error: Connection reset by peer]
<dnadev2> adam12, love it
<dnadev2> :)
<dnadev2> thanks
<adam12> dnadev2: np
* dnadev2 needs to learn how to think like that
<adam12> dnadev2: It's just a few tricks, nothing super surprising.
<adam12> dnadev2: Hash can return a default for missing keys, so we use that to initialize with `0`.
<dnadev2> ahh
<adam12> dnadev2: each_with_object is simpler (imho) to rationalize than reduce/inject because of the argument order. So iterate through each item, passing the item and the same Hash to each block.
<adam12> it probably could of been reduce(Hash.new ...) { |memo, obj| }.
<adam12> If you initialize someting immediately before a loop, then inside the loop, add to it, there's likely an Enumerable method for you. each_with_object, map, etc.
<adam12> And of course, variable_N where N is a number, is generally a good use of a Hash.
<havenwood> dnadev2: @results.tally { |result| result.thing.style }
<dnadev2> adam12, i need to print Enumerable out and paste it on my forehead :)
<dnadev2> just to remember to look into
<havenwood> dnadev2: Check out #tally too.
<adam12> Yeah! Tally is good too. I thought there was another one.
<dnadev2> havenwood, tallyhoe eh?
* dnadev2 tries
<havenwood> dnadev2: We came up with the name "tally" at a camp picnic table at Rails Camp. :)
<adam12> dnadev2: Enumerable should be required reading for every Ruby dev.
<dnadev2> havenwood, hahaha nice on the naming story
<adam12> Does Enumerable#tally take a block?
<havenwood> dnadev2: David Jones is the one who thought of "tally." Matz adopted it right away.
<havenwood> adam12: Oops, no!
<havenwood> adam12: So you'd have to map then tally. :(
<havenwood> adam12: I forgot.
<adam12> Seems like it should...
<havenwood> adam12: I thought it should, but thqt doesn't make it...
<havenwood> adam12: Yeah, agreed.
* dnadev2 hides in the corner after realizing tally ships with 2.7 and this project is 2.5 :/
braincrash has joined #ruby
<havenwood> dnadev2: @results.group_by { |result| result.thing.style }.transform_values(&:size)
<havenwood> Interesting to see how Ruby improves ^ for this task from 1.9 to 2.7.
<dnadev2> that is awesome
<dnadev2> havenwood, that works great, and shorter than each with object :)
<dnadev2> i really should update to get to tally tho, that's slikc
<dnadev2> slick*
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
orbyt_ has joined #ruby
<dnadev2> havenwood, thanks
TCZ has quit [Quit: Diabe? tkwi w szczegó?ach]
helpa has quit [Remote host closed the connection]
helpa has joined #ruby
TomyWork has quit [Remote host closed the connection]
Glumetu has joined #ruby
Glumetu has quit [Client Quit]
dcunit3d has joined #ruby
dnadev2 has quit [Quit: Leaving]
cer0 has joined #ruby
ruby[bot] has quit [Ping timeout: 272 seconds]
teardown_ has joined #ruby
teardown has quit [Ping timeout: 240 seconds]
rippa has joined #ruby
postmodern has quit [Quit: Leaving]
teardown_ has quit [Ping timeout: 240 seconds]
dviola has quit [Ping timeout: 240 seconds]
dviola has joined #ruby
teardown has joined #ruby
Rudd0 has quit [Ping timeout: 258 seconds]
howdoi has joined #ruby
al2o3-cr has quit [Ping timeout: 256 seconds]
bocaneri has quit [Read error: Connection reset by peer]
dviola has left #ruby ["WeeChat 2.9"]
dviola has joined #ruby
akem_ has joined #ruby
akem has quit [Ping timeout: 256 seconds]
akem_ is now known as Istanboule
akem_ has joined #ruby
Istanboule has quit [Ping timeout: 258 seconds]
ur5us_ has joined #ruby
Liothen has joined #ruby
cloud69 has joined #ruby
ruby[bot] has joined #ruby
akem_ is now known as rockinchair
bmurt has quit [Remote host closed the connection]
cgfbee has quit [Ping timeout: 244 seconds]
fippy has joined #ruby
cgfbee has joined #ruby
svilenv has quit [Remote host closed the connection]
rippa has quit [Quit: {#`%${%&`+'${`%&NO CARRIER]
gix has joined #ruby
cliluw has joined #ruby
entel has quit []
entel has joined #ruby
FastJack has quit [Ping timeout: 256 seconds]
FastJack has joined #ruby
bamdad has joined #ruby
howdoi has quit [Quit: Connection closed for inactivity]
ur5us_ has quit [Ping timeout: 260 seconds]
Rudd0 has joined #ruby
TCZ has joined #ruby
cliluw has quit [Ping timeout: 246 seconds]
ur5us_ has joined #ruby
al2o3-cr has joined #ruby
TCZ has quit [Quit: Diabe? tkwi w szczegó?ach]
helpa has quit [Remote host closed the connection]
helpa has joined #ruby
powerhouse has quit [Read error: Connection reset by peer]
also_uplime has quit [Ping timeout: 256 seconds]
powerhouse has joined #ruby
lapsa has joined #ruby
_paul0 is now known as paul0
also_uplime has joined #ruby
lapsa has quit [Remote host closed the connection]
Liothen has quit [Quit: Liothen]
lapsa has joined #ruby
Mia has quit [Ping timeout: 260 seconds]
Liothen has joined #ruby
lapsa has quit [Quit: leaving]
dfucci has quit [Ping timeout: 258 seconds]
cliluw has joined #ruby
lapsa has joined #ruby
dfucci has joined #ruby
BenDover has quit [Quit: BenDover]
moldorcoder7 has quit [Quit: %bye mirc%]
dfucci has quit [Ping timeout: 246 seconds]
moldorcoder7 has joined #ruby
ur5us_ has quit [Ping timeout: 264 seconds]
dfucci has joined #ruby
duderonomy has quit [Ping timeout: 260 seconds]
moldorcoder7 has quit [Ping timeout: 260 seconds]
moldorcoder7 has joined #ruby