jhass[m] changed the topic of #ruby to: Rules: https://ruby-community.com | Ruby 3.1.2, 3.0.4, 2.7.6: https://www.ruby-lang.org | Paste 4+ lines to: https://gist.github.com | Books: https://goo.gl/wpGhoQ
factor has joined #ruby
nirvdrum has joined #ruby
duds- has joined #ruby
<comeoooon> Hello! I have this basic webscraper here: https://clbin.com/lUWfN -- but how do I exit the current iteration in `create_posts` and move on to the next item (incase something isn't right)?
<comeoooon> Sorry if this is too basic of a question :)
<Zerock> comeoooon: ordinarily you would simply write "next" but I don't know what that does in the case of map(). Maybe it inserts nil at that position, but I would test first. Alternatively, it doesn't look like you are actually using the output of map(), so you should probably instead use each(), and "next" would be appropriate there.
<comeoooon> Zerock: Cool, cheers mate!
<comeoooon> Zerock: Here's the full thing for what it's worth: https://gist.github.com/basicfeatures/fa2f425a094756ccd66d2beedf1fbf5c
<comeoooon> Zerock: Replacing map with each seems to work just fine!
<Zerock> okay, and I just did a test. map() will insert nil wherever "next" is encountered
<comeoooon> I see
<comeoooon> Anything else you'd do to improve that script by the way?
<havenwood> I haven't read the full backlog, but seeing #map and next makes me think #filter_map.
<Zerock> havenwood: yeah, the real solution here was to use #each since the result of #map was ignored anyway
<Zerock> comeoooon: I'm a bit occupied at the moment but saw your question. I don't have time to analyze and improve a program right now.
<havenwood> Zerock: That makes sense, and as long as the return value really isn't a filtered map it may be optimal.
<havenwood> Sometimes side effects are the point.
<comeoooon> Very cool guys
<comeoooon> Zerock: Nah, no worries mate! Thank you so much for the help
markong has quit [Ping timeout: 248 seconds]
<havenwood> comeoooon: You can drop the `link =` on the `link = link.attribute("href").value` line.
<havenwood> comeoooon: When you find you have no internal state to instantiate or keep, you can just use a module rather than a class.
<havenwood> comeoooon: Otherwise, looks good.
<comeoooon> Oh nice
<havenwood> module Scraper
<havenwood> def ...
<havenwood> module_function
<havenwood> Then you can Scraper.create_posts(links) etc.
<havenwood> Modules are better when there's no state.
<havenwood> Module functions don't care about the receiver.
<havenwood> And there's no need for a `.new`.
<havenwood> comeoooon: Pry is great, and totally fine to use, but in modern Ruby you can also do `binding.irb` or `require 'debug'` with `debugger`.
<Zerock> do note that the methods in your module should be defined like class methods, i.e. def self.foo
<havenwood> Or `binding.b` or `binding.break` are `debugger` aliases.
<havenwood> Or use module_function, as an alternative
<Zerock> (if you want to use a module as a simple namespace like that, anyway)
<comeoooon> So much valuable info here, thanks guys
<comeoooon> https://gist.github.com/basicfeatures/b39817e0066eae578e20f897dc4d5e9d the script so far (Reddit scraper lol)
<comeoooon> havenwood: No Pry, neat
<comeoooon> Zerock: Will do
<havenwood> comeoooon: another important thing is to use URI.read rather than URI.open.
<havenwood> comeoooon: consider running `rubocop -A` on your code for some linting.
<havenwood> comeoooon: looks good overall.
<havenwood> comeoooon: post an updated code link if you'd like more refined comments
<havenwood> comeoooon: the thinks I'd fail on code review are `URI.open` and `link =` with questions about return values.
<comeoooon> Fantastic :D
<havenwood> things*
<havenwood> and by "fail" I mean "politely comment on", I don't mean to come off harsh
<havenwood> this code is nice to read, and the URI.open is a gotcha
<comeoooon> Oh no by all means. What people sometimes get angry when you try to improve their code? :D
<comeoooon> Thanks, that means a lot. Was under the impression it was a mess (esp the full version)
<gr33n7007h> havenwood: what version of ruby has URI.read
<havenwood> gr33n7007h: all versions
<gr33n7007h> havenwood: i haven't got it
<havenwood> gr33n7007h: require 'open-uri'
<gr33n7007h> havenwood: yeah, with requiring open-uri, i don't seem to have it, weird.
<havenwood> rrr
<havenwood> yeah, you're right. memory is totally failing me here...
<gr33n7007h> havenwood: no worries, i just couldn't remember ever seeing that method.
<havenwood> gr33n7007h: I may be losing my mind here. I need sleep. Heh.
<havenwood> Thank you for the sanity check!
<gr33n7007h> havenwood: not a problem, sleep does the world of good for your brain :)
<havenwood> 100%
<Zerock> is that a gem or is it included with ruby?
<gr33n7007h> Zerock: it's a default gem
<gr33n7007h> Zerock: meaning, they're a part of ruby and can always be required.
<Zerock> neat
Ziyan has joined #ruby
leftylin1 is now known as leftylink
Sankalp has quit [Ping timeout: 252 seconds]
nirvdrum has quit [Quit: nirvdrum]
Sankalp has joined #ruby
nirvdrum has joined #ruby
nirvdrum has quit [Client Quit]
comet23 has joined #ruby
thomas25 has joined #ruby
<thomas25> is gem install supposed to add the executable to PATH? (it does not do that on msys2 windows, it installed the gem into ~/.gem/ruby/2.7.0/gems/ and that's that
<comeoooon> thomas25: I always add it manually to my .zshrc
<thomas25> comeoooon, ok so this is the excpected behavior
<thomas25> and a ruby file has a check `unless defined? (X)` can i define it via env vars?
John_Ivan has quit [Ping timeout: 256 seconds]
abraham has joined #ruby
abraham has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
teclator has joined #ruby
protektwar has joined #ruby
protektwar has quit [Changing host]
protektwar has joined #ruby
ur5us has joined #ruby
comet23 has quit [Quit: Client closed]
ur5us has quit [Ping timeout: 256 seconds]
Linux_Kerio has joined #ruby
gigamo has quit [Quit: WeeChat 3.4]
gigamo has joined #ruby
_ht has joined #ruby
repo1 is now known as repo
pvalenta has quit [Quit: ZNC - https://znc.in]
teclator has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
pvalenta has joined #ruby
Rounin has joined #ruby
Ziyan_ has joined #ruby
Ziyan has quit [Ping timeout: 255 seconds]
pvalenta has quit [Quit: ZNC - https://znc.in]
pvalenta has joined #ruby
arg_ has joined #ruby
ur5us has joined #ruby
mikecmpbll has joined #ruby
ur5us has quit [Ping timeout: 256 seconds]
jpn has joined #ruby
Ziyan has joined #ruby
Ziyan_ has quit [Ping timeout: 256 seconds]
seabre has quit [Ping timeout: 268 seconds]
seabre_ has joined #ruby
spuz has joined #ruby
gr33n7007h has quit [Quit: WeeChat 3.6]
Sankalp- has joined #ruby
Sankalp has quit [Ping timeout: 268 seconds]
Sankalp- is now known as Sankalp
jpn has quit [Ping timeout: 248 seconds]
graywolf has joined #ruby
TomyWork has joined #ruby
Linux_Kerio has quit [Quit: Konversation terminated!]
Linux_Kerio has joined #ruby
jpn has joined #ruby
jhawthorn has quit [Ping timeout: 248 seconds]
jhawthorn has joined #ruby
spuz has quit [Quit: Client closed]
fef has joined #ruby
mikecmpbll has quit [Ping timeout: 248 seconds]
jpn has quit [Ping timeout: 256 seconds]
mikecmpbll has joined #ruby
mikecmpbll has quit [Client Quit]
protektwar has quit [Remote host closed the connection]
protektwar has joined #ruby
protektwar has quit [Changing host]
protektwar has joined #ruby
jpn has joined #ruby
mikecmpbll has joined #ruby
markong has joined #ruby
arg_ has quit [Quit: Connection closed for inactivity]
arg_ has joined #ruby
jpn has quit [Ping timeout: 248 seconds]
Guest61 has joined #ruby
Sankalp has quit [Ping timeout: 248 seconds]
Sankalp has joined #ruby
Guest61 has quit [Quit: Client closed]
jpn has joined #ruby
jpn has quit [Ping timeout: 256 seconds]
Ziyan_ has joined #ruby
Ziyan has quit [Ping timeout: 255 seconds]
graywolf has quit [Quit: WeeChat 3.5]
gr33n7007h has joined #ruby
szkl has joined #ruby
jpn has joined #ruby
jpn has quit [Ping timeout: 248 seconds]
John_Ivan has joined #ruby
entropie has quit [Ping timeout: 240 seconds]
entropie has joined #ruby
jpn has joined #ruby
jpn has quit [Ping timeout: 268 seconds]
protektwar has quit [Ping timeout: 248 seconds]
finsternis has quit [Read error: Connection reset by peer]
jpn has joined #ruby
finsternis has joined #ruby
jpn has quit [Ping timeout: 268 seconds]
bit4bit has joined #ruby
Ziyan has joined #ruby
Ziyan_ has quit [Ping timeout: 244 seconds]
cahoots has joined #ruby
<cahoots> hi, is there a safe way to load untrusted yaml in ruby? like, i don't want any crazy object serialization, i just want cleaner json
<cahoots> i only need to create lists, hashes, and strings
nemesit has quit [Quit: bye]
nemesit has joined #ruby
libsys has quit [Ping timeout: 248 seconds]
libsys has joined #ruby
<mikecmpbll> cahoots; `YAML.safe_load`'ll do it. https://rubyapi.org/3.1/o/psych#method-c-safe_load
jpn has joined #ruby
<cahoots> mikecmpbll, that's that shit i like
<mikecmpbll> ;)
jpn has quit [Ping timeout: 248 seconds]
markong has quit [Ping timeout: 248 seconds]
<depesz> hi. i'm getting : "json-jwt's executable "console" conflicts with rdkafka"
<depesz> is there any way I can force override, but not force disabling dependency check?
rvalue has quit [Read error: Connection reset by peer]
rvalue has joined #ruby
jpn has joined #ruby
jpn has quit [Ping timeout: 248 seconds]
seabre_ has quit [Remote host closed the connection]
jpn has joined #ruby
ssh0732 has quit [Remote host closed the connection]
ssh0732 has joined #ruby
jpn has quit [Ping timeout: 248 seconds]
nemesit has quit [Remote host closed the connection]
gproto23 has joined #ruby
nemesit has joined #ruby
jpn has joined #ruby
jpn has quit [Ping timeout: 256 seconds]
___nick___ has joined #ruby
protektwar has joined #ruby
protektwar has quit [Changing host]
protektwar has joined #ruby
gproto23 has quit [Remote host closed the connection]
arg_ has quit [Quit: Connection closed for inactivity]
jpn has joined #ruby
FetidToot0 has joined #ruby
FetidToot has quit [Ping timeout: 268 seconds]
FetidToot0 is now known as FetidToot
___nick___ has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
___nick___ has joined #ruby
___nick___ has quit [Client Quit]
jpn has quit [Ping timeout: 248 seconds]
___nick___ has joined #ruby
victori has quit [Quit: ZNC 1.8.2 - https://znc.in]
victori has joined #ruby
Ziyan has quit [Ping timeout: 256 seconds]
Ziyan has joined #ruby
fef has quit [Ping timeout: 268 seconds]
jpn has joined #ruby
jpn has quit [Ping timeout: 248 seconds]
protektwar has quit [Ping timeout: 248 seconds]
jpn has joined #ruby
duds- has quit [Ping timeout: 248 seconds]
jpn has quit [Ping timeout: 268 seconds]
bit4bit has quit [Ping timeout: 248 seconds]
duds- has joined #ruby
___nick___ has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
___nick___ has joined #ruby
duds- has quit [Read error: Connection reset by peer]
jpn has joined #ruby
duds- has joined #ruby
jpn has quit [Ping timeout: 256 seconds]
jpn has joined #ruby
Inoperable has quit [Excess Flood]
Furai has quit [Quit: WeeChat 3.6]
Inoperable has joined #ruby
ollysmith_ has quit [Quit: ZNC 1.8.2+deb2+b5 - https://znc.in]
jpn has quit [Ping timeout: 268 seconds]
ollysmith has joined #ruby
jpn has joined #ruby
Furai has joined #ruby
protektwar has joined #ruby
protektwar has quit [Changing host]
protektwar has joined #ruby
TomyWork has quit [Remote host closed the connection]
protektwar has quit [Ping timeout: 256 seconds]
polishdub has quit [Quit: leaving]
<havenwood> depesz: The funny thing is that json-jwt doesn't mean to ship a `console` executable.
<havenwood> depesz: The RubyGems default for executables is `spec.bindir = 'bin'` but json-jwt follows the Bundler convention of using `bin/, which should come with modifying the default to `spec.bindir = 'exe'` but the author didn't do that.
<havenwood> I think they just didn't realize the RubyGems and Bundler conventions conflict. It causes an issue here.
<havenwood> depesz: Maybe do a PR to the gem with `spec.bindir = 'exe'` to fix the issue upstream?
<havenwood> This appears inadvertent.
jpn has quit [Ping timeout: 256 seconds]
polishdub has joined #ruby
jpn has joined #ruby
arg_ has joined #ruby
polishdub has quit [Quit: leaving]
polishdub has joined #ruby
_ht has quit [Remote host closed the connection]
___nick___ has quit [Ping timeout: 256 seconds]
Ziyan has quit [Quit: Textual IRC Client: www.textualapp.com]
Furai has quit [Quit: WeeChat 3.6]
gigamo has quit [Quit: WeeChat 3.6]
gigamo has joined #ruby
hightower3 has joined #ruby
hightower4 has quit [Ping timeout: 256 seconds]
cocalero has joined #ruby
cocalero_ has joined #ruby
curio has joined #ruby
arg_ has quit [Quit: Connection closed for inactivity]
markong has joined #ruby
Furai has joined #ruby
cahoots has quit [Ping timeout: 256 seconds]
Furai has quit [Quit: WeeChat 3.6]
Furai has joined #ruby
EternalSunshine has joined #ruby
Linux_Kerio has quit [Ping timeout: 248 seconds]
Rounin has quit [Ping timeout: 256 seconds]
markong has quit [Ping timeout: 256 seconds]