<John_Ivan>
is there a keyword in ruby that lets you repeat the same iteration in a loop?
<John_Ivan>
e.g "repeat" and have the same loop restart at the beginning, having the same state (e.g iteration counter being the same)
<John_Ivan>
I have some code that is executing and fails. I wish to re-repeat the same code but from the start of the loop, without altering the iteration counter.
<John_Ivan>
actually. nevermind. I'll just wrap it up in a while() loop.
ssh073 has quit [Remote host closed the connection]
ssh073 has joined #ruby
<adam12>
John_Ivan: loop ?
<adam12>
oh. nevermind. I see you want something a bit more advanced.
<John_Ivan>
adam12, just something like "for x in 1..5 do #a; #b; #c; end" where I would have wanted to execute #a, #b, #c again, but with the same counter it's at.
<adam12>
John_Ivan: Maybe you can cycle.
<John_Ivan>
e.g if x was 3, to call "repeat" and have the loop start again from the top. but still with 3.
<adam12>
Seems kind of XY. What are you trying to retry and what's the counter for?
<adam12>
Maybe this is as simple as 1..5.times and the redo keyword.
dionysus69 has quit [Quit: dionysus69]
dionysus70 has joined #ruby
<John_Ivan>
adam12, I have solved it with a while() loop so it's fine. thank you :)
<adam12>
John_Ivan: Curious what the solution ended up being?
dionysus70 has quit [Ping timeout: 256 seconds]
<John_Ivan>
adam12, while(true) ... if (error) next; end iterator++
<John_Ivan>
next will just repeat the while loop on the same iterator.
<adam12>
John_Ivan: Where do you set up the iterator value? outside the while loop?
<John_Ivan>
yup. and iterate it inside the loop.
<adam12>
You can use `loop` instead of `while true` here.
<John_Ivan>
adam12, the "loop" keyword?
<adam12>
Is the iterator just an Integer?
<John_Ivan>
yes
TasiMobile has joined #ruby
TasiMobile has quit [Client Quit]
<John_Ivan>
if "loop" was the answer, well, dang :D
<adam12>
Does it have a range or is it infinite?
<John_Ivan>
adam12, it can be a situation of both. in this case, infinite.
<adam12>
John_Ivan: Ah. I think redo might have worked as well, with an Enumerator.
rvalue has joined #ruby
<John_Ivan>
adam12, here is my code. warning: a mess.
<John_Ivan>
the loop I'm talking about begins at "while(true)"
<adam12>
John_Ivan: Hey, we all write quick and dirty code. It's no big deal.
<John_Ivan>
adam12, the place where I needed the "redo" is where I use "next", right in the if statement's else under the caught exceptions. there's only 2 of them.
<John_Ivan>
adam12, context: my spider collects my manga. it starts by not knowing how many images a particular artists' work has
<John_Ivan>
adam12, so it iterates (to 20000 originally because why not) infinitely until if encounters a 404
<John_Ivan>
that marks the end of a particular work
<adam12>
John_Ivan: I think your solution is fine.
<John_Ivan>
adam12, the problem is, a particular request may fail (network error, 429, 503, whatever)
<John_Ivan>
so I'd want to delete the amount of manga downloaded
<John_Ivan>
because I won't bother counting backwards how many pages I took, although it would be much simpler...
<John_Ivan>
but instead I say
<adam12>
John_Ivan: If you were looking for improvements, I'd probably start decomposing this into smaller methods with some names. Then you could move behaviour closer to its locality.
<John_Ivan>
"throw away the entire work. keep track of the counter. restart that work's download."
<John_Ivan>
adam12, yeah. definitely. but no, not looking for improvements. at least, not with this script.
<John_Ivan>
it's a fire and forget spider.
<adam12>
Cool.
<John_Ivan>
adam12, stuff tends to dissapear off the internet
<John_Ivan>
wrote this really fast as I don't want to see my favourites dissapear :P
<John_Ivan>
the quicker I start downloading, the better.
<adam12>
John_Ivan: Indeed. I've actually taken to sending _every_ Ruby article I read through archive.is.
<adam12>
Because the bitrot is real.
<John_Ivan>
aye
<adam12>
And I like reading stuff from years ago.
dionysus69 has joined #ruby
<John_Ivan>
for me, the manga is on a website that does #piracy so chances of it dissapearing are very high (especially when this is the 4th time the website was put back up)
<John_Ivan>
and I have like 5k mangas to download
<John_Ivan>
each with averaging 80+ pages.
<adam12>
Shame it's not just available as a torrent. Oh well.
<John_Ivan>
adam12, it is. but their content is messy.
<John_Ivan>
and they offer torrent per manga rather than torrent for everything.
<John_Ivan>
adam12, it does*
<adam12>
Ah.
wand has joined #ruby
oxfuxxx has joined #ruby
tekkconvos has joined #ruby
<tekkconvos>
Hi, I have some strange issue. I'm using Net::HTTP inside a class, it works fine as is... but as soon as I try to invoke a simple .get() within a docker container ruby environment I get: `getaddrinfo: Name or service not known`. The hostname is resolvable and curl inside the same container works. Trying to debug this but running out of ideas.
<tekkconvos>
I'm using URI.parse(my_url) followed by URI.encode_www_form(params) and then a Net::HTTP.get_response() with that URI.
<adam12>
tekkconvos: What Ruby version? and the hostname, is it something local via Docker (ie another container via the service fabric) or is it something external, like google.com?
<tekkconvos>
ruby 2.7.4 from package repo's. Its reaching to an external service. (such as google in your example)
<tekkconvos>
http (not https)
<tekkconvos>
exact same code works fine when ran outside a containerised environment (I tried only docker, but on 2 different hosts)
<adam12>
tekkconvos: What happens if you call Resolv directly? ruby -rresolv -e 'p Resolv.getaddress("yourgoogle.com")'
<tekkconvos>
good idea 1 sec
<tekkconvos>
that works, its also worth mentioning, if I put in the IP directly instead of the hostname, I still get the same error, which is odd as it should not be attempting a lookup
<adam12>
Maybe it's IPv6 and happy eyeballs related.
<adam12>
Oh. With IP it's broken too. Hmm.
<tekkconvos>
haha, no IPv6 here (or on the remote host), but yes could be
<tekkconvos>
is there a way to get Net::HTTP (or ruby) to spit out more debug info?
<tekkconvos>
with IP (no hostname) it still fails on getaddrinfo btw.
<adam12>
Not sure, but you could maybe enable tracer and see if it helps at all. gem install tracer; irb --tracer; run your commands.
<tekkconvos>
although I just noticed a "twerk"
<tekkconvos>
"qwerk"
<tekkconvos>
even
<adam12>
I wonder if you `curl -vvvv` it would show a hint.
<tekkconvos>
my URL contains a non standard port
<adam12>
Oh. Yes, that might be it.
<tekkconvos>
once it runs through URI.parse a standard port is attached :80
<tekkconvos>
I think that may be it
<adam12>
It's resolving foobar:80
<tekkconvos>
yup
<adam12>
which is obviously failing. Shame the error message isn't nicer. Maybe worthy of a PR to net/http
<tekkconvos>
but getaddrinfo still a strange result
<adam12>
I wonder how URI is parsing that port. Because it has no scheme? or does it?
<tekkconvos>
In fact, the URI object is fine, its Net::HTTP.get_response() that is injecting the :80
<adam12>
Ooh.
<adam12>
Maybe get_response expects a String.
<adam12>
Hmm nope. I'm not sure.
<adam12>
What's the exact way you're calling #get_response, out of curiosity.
<tekkconvos>
oh this is getting more interesting (after your last hint)
<tekkconvos>
Net::HTTP.get_response(uri.to_s) is whats failing.... it works on my local machine (a Mac)... however inside the container, if I pass it a URI object rather than a String... it works
<tekkconvos>
perhaps its a ruby 3.x vs ruby 2.x thing
<tekkconvos>
and Net::HTTP went from expecting URI to String or something
<kenichi>
curious if this is a resolv-replace use case
<tekkconvos>
still, the error message is not great.
Milos has quit [Ping timeout: 246 seconds]
<tekkconvos>
I did try resolv-replace but perhaps not correctly
Milos has joined #ruby
<tekkconvos>
I need to support both Ruby 2.x and Ruby 3.x ideally, will look into a conditional way of doing so that is inside the script rather than elsewhere
<tekkconvos>
(no implicit conversion of URI::HTTP into String)... this is getting even stranger...
<adam12>
Net::HTTP.get_response(uri) is causing issues?
<tekkconvos>
no
<tekkconvos>
Net::HTTP.get() now
oxfuxxx has quit [Ping timeout: 252 seconds]
<adam12>
Ah.
<tekkconvos>
interestingly, I'm getting different behaviour in irb when running in-line vs loading the class
<tekkconvos>
rubber ducking at this point, but getting closer
<tekkconvos>
I mean, the lazy option would be to move to HTTParty or something, but I didn't wanna give up on Net::HTTP that easily after several decades of its existence
<tekkconvos>
I bet if I use Net::HTTP "the old way" with separate host port path suffix fields it'd work
<adam12>
I wish net/http saw more usage, but I feel like it's half abandonded. I still use it where possible, but that's because any large enough Ruby application ends up with 5+ transitive http client dependencies.
<RickHull>
I've noticed a difference in behavior in mruby, relative to MRI (and older versions of mruby). different results of floating point operations
<RickHull>
older mruby and MRI yield 0.0, but mruby master yields 2.22044604925031e-16
<RickHull>
before I try to come up with a simpler test case and file an issue -- is there any good reason this is expected behavior?
ollysmith has quit [Quit: ZNC 1.8.2+deb2+b4 - https://znc.in]
ollysmith has joined #ruby
protektwar has quit [Ping timeout: 252 seconds]
oxfuxxx has joined #ruby
oxfuxxx has quit [Client Quit]
dviola has joined #ruby
jtdowney has joined #ruby
jpn has joined #ruby
Ziyan has quit [Ping timeout: 260 seconds]
Ziyan has joined #ruby
<havenwood>
RickHull: I can't think of a reason.
<RickHull>
i see there are some flags introduced for float behavior, and my old mruby was like 5 years old
<weaksauce>
which calculations?
<RickHull>
mruby 1.3ish from 2017
<RickHull>
hard to say, I'm tracing them now
ssh073 has quit [Ping timeout: 240 seconds]
<RickHull>
to reproduce: clone this repo, get it set up (pretty easy). then `rake timed_simplex` should exit cleanly. update the mruby submodule; clean and rebuild; then `rake timed_simplex` fails