<cloud69>
trying to clean this url that starts with just // and not http://
<apotheon>
Yes, that's what that code should do.
<apotheon>
s/output/return/
adu has joined #ruby
<cloud69>
ah. my irb wasn't outputting anything due to a prior failed command
<apotheon>
ah
<cloud69>
apotheon: cool. i get the same result with gsub(/\//, "") as gsub(/\/\//, "") though
<apotheon>
By the way, a way to make a regex less confusing to read is to do something like:
<apotheon>
Regexp.new('//')
<apotheon>
(depending on context, sometimes that's less painful)
<cloud69>
nice, didn't know that
<cloud69>
oh and one more thing:
<apotheon>
The difference between gsub(/\/\//, "") and gsub(/\//, "") is that the latter will also remove all slashes, even if there's only one of them.
<apotheon>
Thus, if you have //lala/titi/dodo/ the result will be lala/titi/dodo for the first gsub and lalatitidodo for the second gsub.
<apotheon>
Many people don't like pastebin.com for pastes.
<cloud69>
i'll make the change asap :)
<cloud69>
gsub(/\/\//, "") it is then, thx
<apotheon>
In fact, today pastebin.com has decided that I'm not allowed to view your paste and gave me a broken captcha.
<apotheon>
Oh, the captcha worked on the second try.
<cloud69>
:/ apologize for the inconvenience
<cloud69>
i wonder if rails has a helper to turn strings into valid urls
<cloud69>
like .strip or .parameterize
<apotheon>
You could turn product.css('#content').css('.foo').text.gsub(...) into a method thta takes '.foo', '.bar', and '.baz' as an argument and returns a result for assignment to each variable.
chouhoulis has quit [Ping timeout: 264 seconds]
<cloud69>
apotheon: maybe thats a bit overboard. im ok repeating myself in this case
<cloud69>
cheers!
adu has quit [Quit: adu]
glimpse[m] has joined #ruby
<apotheon>
You could also create a hash, thing = {name: 'foo', price: 'bar', description: 'baz'}, then operate on it with thing.keys.each {|k| thing[k] = product.css("#content").css(".#{think[k]}").text.gsub(...) }
<apotheon>
. . . which would give you those results, but instead of variables name, price, and description, you'd have think[:name], thing[:price], and thing[:description].
<apotheon>
note: The code was correct in my head, but may not have arrived in IRC true to form, and I did not test it.
<apotheon>
Doing it with each_pair might result in a race condition. I'm not sure.
<apotheon>
. . . and, alas, there's no #pairs method.
<cloud69>
hehe true to form :)
<cloud69>
seems a bit overboard to be honest but looks like a nice exercise though!
<cloud69>
last thing, I'm getting `undefined method `gsub' for #<Nokogiri::XML>` when trying to either `main_image_url = product.css("#content").css("a").attr("href").gsub(...)`
<cloud69>
Or when creating a new variable and using URI.escape like `main_image_url2 = URI.escape(main_image_url.gsub(/\/\//, ""))` anybody know?
<cloud69>
i reckon nokogiri doesn't support gsub, but shouldn't the uri escape thing mitigate that?
roshanavand has quit [Ping timeout: 260 seconds]
orbyt_ has joined #ruby
lucasb has quit [Quit: Connection closed for inactivity]
<cloud69>
nevermind i got it
DaRock has joined #ruby
<cloud69>
added a new line `main_image_url = main_image_url.attribute("href").value.gsub(/\/\//, "")`
Azure has quit [Ping timeout: 260 seconds]
Azure has joined #ruby
KindOne has left #ruby [#ruby]
<cloud69>
Anybody know why I'm getting `Errno::ENOENT: No such file or directory @ rb_sysopen - cdn.shopify.com/s/files/1/1752/6725/products/foobar.jpg` for `main_image = URI.open(main_image_url)` in the following snippet? https://pastebin.com/iKSKKcmD
<cloud69>
Yes, I'm working on setting up a GitHub account as we speak :)
helpa has quit [Remote host closed the connection]
helpa has joined #ruby
factormystic has quit [Ping timeout: 256 seconds]
<apotheon>
cloud69: I tend to want to deduplicate any time I see something like three lines in a row of code like `product.css('#content').css(one_thing_that_changes).text.gsub(...)` because if it ever turns out that code needs to change I'd need to change it in three places, which means there are three opportunities for me to get it wrong without noticing.
<apotheon>
cloud69: . . . so I'm not sure it's overboard.
<apotheon>
cloud69: I don't think you need a GitHub account for gists, but maybe I'm mistaken.
<apotheon>
cloud69: You could also use something like sprunge for pastes if you don't want to use gists.
<apotheon>
cloud69: There's no signing in, and it's about as simple as can be. You can use a simple script to submit code from the command line for it.
<apotheon>
cloud69: My personal preference is just for people's pastes to not require JavaScript in the browser.
<cloud69>
yeah i can understand that. http://sprunge.us/ looks awesome, im gonna use that from now on
mozzarella has quit [Remote host closed the connection]
<apotheon>
cloud69: With that, I can pipe output of some command to it, like `command | sprunge`; I can just give it a filename, like `sprunge filename.rb`; and I can just use `sprunge` and type or paste code to it directly (and hit Ctrl-D on a blank line at the end to make it paste to the website).
<PSchlesinger>
Anybody here developing on MacOS? I'm going nuts trying to get syslogger to log debug to system.log (or to a particular log file after editing asl.conf). Best I can get is warn or better in the Console.app. Help?
AnomalyXII has joined #ruby
SanguineAnomaly has quit [Ping timeout: 260 seconds]
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
powerhouse has quit [Quit: Leaving]
powerhouse has joined #ruby
ChmEarl has quit [Quit: Leaving]
gix has joined #ruby
gix- has quit [Ping timeout: 265 seconds]
ur5us_ has quit [Ping timeout: 260 seconds]
gix has quit [Ping timeout: 260 seconds]
baojg_ has joined #ruby
<PSchlesinger>
Anybody here developing on MacOS? I'm going nuts trying to get syslogger to log debug to system.log (or to a particular log file after editing asl.conf). Best I can get is warn or better in the Console.app. Help?
baojg has quit [Ping timeout: 264 seconds]
ScotchBonnet has joined #ruby
<ScotchBonnet>
Hello. Could anybody give me some advice on how to achieve the same functionality as https://quillbot.com/ in Ruby?
<ScotchBonnet>
I see most language processors on GitHub are made in Python :/
donofrio has quit [Remote host closed the connection]
adu has quit [Quit: adu]
cer0 has quit [Quit: leaving]
donofrio has joined #ruby
chouhoulis has quit [Remote host closed the connection]
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
podman has quit [Read error: Connection reset by peer]
podman has joined #ruby
iNs has quit [Remote host closed the connection]
iNs has joined #ruby
iNs has quit [Remote host closed the connection]
iNs has joined #ruby
evdubs_ has joined #ruby
evdubs has quit [Ping timeout: 264 seconds]
<PSchlesinger>
Anybody here developing on MacOS? I'm going nuts trying to get syslogger to log debug to system.log (or to a particular log file after editing asl.conf). Best I can get is warn or better in the Console.app. Help?
baojg_ has quit [Remote host closed the connection]
baojg has joined #ruby
hagabaka has quit [Quit: No Ping reply in 180 seconds.]
hagabaka has joined #ruby
akem has quit [Ping timeout: 256 seconds]
dviola has quit [Ping timeout: 272 seconds]
dviola has joined #ruby
s2013 has joined #ruby
chouhoulis has joined #ruby
chouhoulis has quit [Ping timeout: 272 seconds]
vondruch has joined #ruby
ur5us_ has joined #ruby
Glumetu has joined #ruby
Lyubo1 has joined #ruby
evdubs_ is now known as evdubs
Fire-Dragon-DoL has quit [Ping timeout: 260 seconds]
s2013 has quit [Quit: My Mac has gone to sleep. ZZZzzz…]