AndreYuhai

Activity Graph

Page 1 of 2 | Next »

2019-08-13

[22:23:11] AndreYuhai: has joined #ruby
[22:24:33] AndreYuhai: Hey there, I have a class and I am including a module to create database tables. But for example I will need more than 2 create table methods each of them creating a different table. How can I separate them using namespaces or modules? I got a bit confused.
[22:29:08] AndreYuhai: I mean how can I use my create_table method like ModuleName.create_table ? Because when I make it a class method then I can not use the instance variable from the class in which I am including the module.
[23:22:35] AndreYuhai: Quit: Leaving

2019-07-19

[00:56:38] AndreYuhai: Remote host closed the connection
[00:57:00] AndreYuhai: has joined #ruby
[01:15:38] AndreYuhai: Remote host closed the connection
[01:16:00] AndreYuhai: has joined #ruby
[02:01:38] AndreYuhai: Remote host closed the connection
[02:02:01] AndreYuhai: has joined #ruby
[02:15:38] AndreYuhai: Remote host closed the connection
[02:16:02] AndreYuhai: has joined #ruby
[05:48:42] AndreYuhai: Read error: Connection reset by peer

2019-07-18

[04:26:09] AndreYuhai: Remote host closed the connection
[04:26:29] AndreYuhai: has joined #ruby
[04:35:39] AndreYuhai: Remote host closed the connection
[04:36:00] AndreYuhai: has joined #ruby
[16:11:39] AndreYuhai: Remote host closed the connection
[16:12:00] AndreYuhai: has joined #ruby
[21:19:21] AndreYuhai: has joined #ruby
[21:19:59] AndreYuhai: Hey there, how do I throw an exception out of my function? Just like in Java like public int foo () throws ...
[21:29:47] AndreYuhai: leftylink: Nope, to be more clear, I have a class called "Database" using the gem "Mysql2" and in that class I have a function called insert_into_table. So I am using this "Database" class in another class to insert some data into my table.
[21:30:10] AndreYuhai: But when the data is duplicate I get an exception. I want to pass this exception to the calling class
[21:31:06] AndreYuhai: leftylink: So do I just rescue StandardError => e; raise e; end ?
[21:31:19] AndreYuhai: I mean inside the begin block of course
[22:07:38] AndreYuhai: Remote host closed the connection
[22:08:00] AndreYuhai: has joined #ruby
[22:15:38] AndreYuhai: Remote host closed the connection
[22:15:58] AndreYuhai: has joined #ruby

2019-07-17

[15:22:48] AndreYuhai: has joined #ruby
[15:23:49] AndreYuhai: Hey there, I hava an address column in my database table, I would like to extract the country, city and state names. How would I go about it given that there is not a pattern to use regexp.
[15:24:33] AndreYuhai: I've tried to look up for a gem and I've found one called city-state but does not seem to work.
[18:55:39] AndreYuhai: Remote host closed the connection
[18:56:01] AndreYuhai: has joined #ruby
[19:35:39] AndreYuhai: Remote host closed the connection
[19:35:58] AndreYuhai: has joined #ruby

2019-07-13

[04:50:38] AndreYuhai: Remote host closed the connection
[04:50:58] AndreYuhai: has joined #ruby
[04:59:08] AndreYuhai: Remote host closed the connection
[04:59:30] AndreYuhai: has joined #ruby
[07:26:04] AndreYuhai: Quit: Leaving

2019-07-12

[13:08:47] AndreYuhai: has joined #ruby
[13:09:09] AndreYuhai: Hi there, how do I loop through months instead of all all the days withing the two months?
[13:09:50] AndreYuhai: for example : 2019, 05 -> 2019, 07 I want to loop through 2019, 05 / 2019, 06 / 2019, 07
[13:10:04] AndreYuhai: date.downto or upto loops through all the days
[13:27:03] AndreYuhai: al2o3-cr: Thank you.
[17:43:38] AndreYuhai: Remote host closed the connection
[17:43:57] AndreYuhai: has joined #ruby
[17:49:08] AndreYuhai: Remote host closed the connection
[17:49:31] AndreYuhai: has joined #ruby

2019-06-25

[07:43:25] AndreYuhai: Remote host closed the connection
[07:43:54] AndreYuhai: has joined #ruby
[10:54:57] AndreYuhai: Ping timeout: 248 seconds
[23:10:40] AndreYuhai: has joined #ruby
[23:11:41] AndreYuhai: hey there I am tryinng to scrape aliexpress and there is this slidebar to prevent bots. But even though I can slide it using watir I still get an error. And sometimes I get it even when I try manually, any idea as to why and how to prevent it? https://imgur.com/a/FudHjFW
[23:38:16] AndreYuhai: Remote host closed the connection

2019-06-24

[17:21:45] AndreYuhai: has joined #ruby
[17:23:32] AndreYuhai: Hi there, I am using Watir to navigate to Aliexpress but sometimes I get this slidebar to slide it to right, however even if slide it manually I still get the error message in the picture. Any idea as to why? This even happens when I am not using watir or any other automation but just manually navigating to Aliexpress https://imgur.com/a/FudHjFW
[19:15:44] AndreYuhai: how do I rescue net::readtimeout error?

2019-06-19

[00:25:54] AndreYuhai: Remote host closed the connection
[00:26:13] AndreYuhai: has joined #ruby
[00:27:54] AndreYuhai: Remote host closed the connection
[00:28:18] AndreYuhai: has joined #ruby
[00:47:54] AndreYuhai: Remote host closed the connection
[00:48:16] AndreYuhai: has joined #ruby
[00:56:24] AndreYuhai: Remote host closed the connection
[00:56:45] AndreYuhai: has joined #ruby
[00:57:54] AndreYuhai: Remote host closed the connection

2019-06-18

[14:21:39] AndreYuhai: has joined #ruby
[14:21:50] AndreYuhai: Hello there, can I use regexp in xpath?
[18:26:48] AndreYuhai: How do I keep selecting from the nodeset that I have in hand using xpath? For example I am looking for an a tag in h2. I've selected h2 but a is not the immediate element after h2, how do I select it?
[23:39:24] AndreYuhai: Remote host closed the connection
[23:39:51] AndreYuhai: has joined #ruby
[23:57:54] AndreYuhai: Remote host closed the connection
[23:58:13] AndreYuhai: has joined #ruby

2019-06-15

[02:57:42] AndreYuhai: Remote host closed the connection
[02:58:01] AndreYuhai: has joined #ruby
[03:07:42] AndreYuhai: Remote host closed the connection
[03:08:01] AndreYuhai: has joined #ruby
[05:55:12] AndreYuhai: Remote host closed the connection
[05:55:31] AndreYuhai: has joined #ruby
[05:58:12] AndreYuhai: Remote host closed the connection
[05:58:30] AndreYuhai: has joined #ruby
[06:29:42] AndreYuhai: Remote host closed the connection
[06:30:05] AndreYuhai: has joined #ruby
[06:37:55] AndreYuhai: Remote host closed the connection
[06:38:03] AndreYuhai: has joined #ruby
[06:40:12] AndreYuhai: Remote host closed the connection
[06:40:35] AndreYuhai: has joined #ruby
[06:47:42] AndreYuhai: Remote host closed the connection
[06:48:04] AndreYuhai: has joined #ruby
[15:57:07] AndreYuhai: Ping timeout: 245 seconds

2019-06-14

[00:29:10] AndreYuhai: phaul: I wrote the setter for my instance variable as you suggested. But why can I not use it in my initialize? I mean it didn't work this way.
[08:16:30] AndreYuhai: phaul: Can you take a look at this ? https://paste.ofcode.org/RqAXcvvqpf9Z46XUjre7Q3
[08:20:24] AndreYuhai: phaul: Yes, this does not work. It simply assigns the values to the instance variables without evaluating them with my setter methods as if they don't exist.
[08:24:43] AndreYuhai: phaul: But with self wouldn't it be a class method?
[08:28:50] AndreYuhai: Now I am confused. :D And I guess it didn't work either.
[08:31:45] AndreYuhai: phaul: Yes I did. I converted them into self.method=(foo) but they still get set directly.
[08:32:03] AndreYuhai: phaul: And I found this answer, https://stackoverflow.com/a/10465235/4796762
[08:35:59] AndreYuhai: phaul: When I set the value using the method like obj.file_date = '04/01/2019' then it works and gives me => '2019-04-01' but I don't know why in initialization it does not work.
[08:36:27] AndreYuhai: phaul: oh let me check. I hadn't change the methods in initializer
[08:36:32] AndreYuhai: to self.method
[08:40:56] AndreYuhai: phaul: Now it works. Thank you. But what is the difference between using self.method and @variable_name? Because one uses the setter method we wrote and the other one just assigns the value and I didn't even have a attr_accessor
[08:41:06] AndreYuhai: or attr_writer
[08:44:12] AndreYuhai: phaul: Hahaha thank you, I added it to my watch list! :) Thanks for the help!
[09:42:24] AndreYuhai: How do I escape a single quote in my string with gsub or etc.? :D gsub("'", "\'") does not work
[09:47:23] AndreYuhai: wow that's a lot of backslashes haha. Thank you once again. :)
[11:02:11] AndreYuhai: Remote host closed the connection
[11:06:29] AndreYuhai: has joined #ruby

2019-06-13

[20:11:50] AndreYuhai: has joined #ruby
[20:13:00] AndreYuhai: Hello there, I am using mysql2 gem. I want to insert NULLs when the string is empty. How to achieve this? I mean if I do string interpolation in my INSERT query then I will have quotes but when NULL put in quotes it is not treated as NULL.
[20:13:28] AndreYuhai: I couldn't come up with a good way of implementing this idea and I couldn't find anything on the Internet.
[20:14:58] AndreYuhai: the default is already NULL. but then if I skip that in my INSERT query then what if in a case where the string is not empty. Because INSERT query is hard coded.
[20:17:19] AndreYuhai: Oh, maybe I could just put strings in quotes before interpolating them in insert query so that I can also convert empty strings to NULL! I will try that and see.
[20:37:38] AndreYuhai: Remote host closed the connection
[20:37:56] AndreYuhai: has joined #ruby
[20:48:08] AndreYuhai: Remote host closed the connection
[20:48:27] AndreYuhai: has joined #ruby
[21:12:38] AndreYuhai: Remote host closed the connection
[21:13:01] AndreYuhai: has joined #ruby
[21:27:38] AndreYuhai: Remote host closed the connection
[21:27:59] AndreYuhai: has joined #ruby
[21:38:08] AndreYuhai: Remote host closed the connection
[21:38:30] AndreYuhai: has joined #ruby
[21:48:08] AndreYuhai: Remote host closed the connection
[21:48:30] AndreYuhai: has joined #ruby
[21:57:43] AndreYuhai: How to check if a string is just containing white space? Strip does not help.
[21:59:03] AndreYuhai: phaul: oh, that's right. Thanks.
[22:38:16] AndreYuhai: havenwood: This is actually what I was looking for just now. I guess using this regexp : /\A\s*\Z/ does not work for &nbsp
[22:43:00] AndreYuhai: I don't know why it does not work but I just figured it out. Hopefully the first string I got had this &nbsp. :D
[23:27:53] AndreYuhai: How can I check a value or change it before I assign it to my instance variable that is declared with attr_accessor? Should I override variable_name= ?
[23:36:00] AndreYuhai: phaul: oh that looks better, thank you. :)

2019-06-12

[08:09:01] AndreYuhai: Remote host closed the connection

2019-06-11

[16:48:09] AndreYuhai: has joined #ruby
[16:49:36] AndreYuhai: Hello there, I have a script and I want it to run everyday. And the script needs user input. Can I do it without using cronjob or sleep?
[17:00:54] AndreYuhai: havenwood: Well, I don't know if there is any pros or cons to sleep so I wanted to ask whether there are other ways to do it. The input would either be two dates or one date (that day's date). So I also do not know whether I can also get the date automatically for the cronjob. But I am searching and I will also check that gem. Thank you :)
[17:06:15] AndreYuhai: havenwood: But would it still do that if we specify an exact date? Instead of saying 24 hours. I mean by checking the actual date and etc.
[18:19:44] AndreYuhai: havenwood: Yes, for example sleeping for a period of time and checking the date constantly, for example sleeping for a few hours instead of 24. Sorry for the delay by the way.
[18:25:41] AndreYuhai: havenwood: Oh that is a good idea as well. I guess I will go with the cronjob but I will also check the timer gem. Thank you. By the way would there be any consequence of using 'sleep' on the server side compared to cronjobs?
[18:28:44] AndreYuhai: havenwood: Okay, thanks for the help. :) I will also check the timers gem and then decide which one to use.

2019-05-31

[15:35:11] AndreYuhai: Remote host closed the connection
[15:35:38] AndreYuhai: has joined #ruby
[15:37:37] AndreYuhai: Remote host closed the connection

2019-05-30

[12:09:15] AndreYuhai: Remote host closed the connection
[12:09:38] AndreYuhai: has joined #ruby
[12:37:45] AndreYuhai: Remote host closed the connection
[12:38:08] AndreYuhai: has joined #ruby
[15:44:45] AndreYuhai: Remote host closed the connection
[15:45:06] AndreYuhai: has joined #ruby
[15:47:45] AndreYuhai: Remote host closed the connection
[15:48:08] AndreYuhai: has joined #ruby

2019-05-29

[13:50:32] AndreYuhai: has joined #ruby
[14:07:29] AndreYuhai: Hello there, I am trying to get all the links from a web page using mechanize. The question is when the link is something like "http://foo.com/#bar" this link is okay but when the link also has spaces like "http://foo.com/#bar qux" then it gets '#' and 'space' characters gets replaced with '%23' and '%20'. Is there any way to prevent this or should I switch to addressable gem?
[14:17:32] AndreYuhai: havenwood: but the '#' doesn't get decoded back, right? I mean when it is space and %20 when you navigate to that link space becomes a space in the address bar again. But hashtag does not get decoded.
[14:22:08] AndreYuhai: havenwood: But for example: 'https://avc.com/%23post-18810' This says page not found.
[14:22:31] AndreYuhai: havenwood: But this 'https://avc.com/#post-18810' works
[14:32:08] AndreYuhai: havenwood, jhass So what I was trying to say is when I use mechanize and get the links if there is this fragment part then URI module encodes it, but I guess it shouldn't be encoded then.
[14:32:37] AndreYuhai: And it only encodes when you have space too. I mean if you do not have any space then it does not encode.
[14:33:29] AndreYuhai: For example if you have "...com/#section" this does not get encoded, but "...com/#section ruby" gets encoded as "23%section%20ruby"
[14:39:58] AndreYuhai: jhass: How can I fix this then? I am lost. :D
[14:40:36] AndreYuhai: I mean if I don't fix it then the URL I request is wrong so I can't view that page.
[14:49:08] AndreYuhai: jhass: Oh, that is right though. Haha, I can just ignore the fragment as you said since it doesn't really make sense anyway to have the fragment.
[14:50:39] AndreYuhai: jhass: I am not really scraping the content though. I am just trying to get all the links from each page using BFS just for fun. The page is my blog page blog.andreyuhai.com
[15:01:11] AndreYuhai: jhass: Well, actually I just tried it. Since URI encodes even the fragment part then URI module does not recognize the fragment part afterwards haha. Even to_s returns the encoded string. I will try with addressable and see.

2019-04-28

[21:28:56] AndreYuhai: has joined #ruby
[21:31:58] AndreYuhai: Hello there, I have this example string "J & M AUTO BODY" that I need to add to my query string for making requests. But using CGI.escape or URI.escape does not work as expected. CGI.escape gives me "J+%26+M+AUTO+BODY", URI.escape gives me "J%20&%20M%20AUTO%20BODY". Is there a way to escape '&' instead of gsub and etc.?
[21:38:28] AndreYuhai: havenwood: I just want to escape ampersand properly as it should be. & => %26
[21:38:55] AndreYuhai: I mean gsub works as well but I was wondering whether there is any other way.
[21:41:52] AndreYuhai: &>> URI.escape 'J & M AUTO BODY', '& '
[21:42:20] AndreYuhai: havenwood: This worked as expected but I didn't know about that second parameter. Thanks I will check out the docs.
[21:59:32] AndreYuhai: Quit: Leaving

2019-04-17

[01:44:38] AndreYuhai: Ping timeout: 245 seconds

2019-04-16

[16:38:52] AndreYuhai: has joined #ruby
[16:41:33] AndreYuhai: I have an each loop and then I am rescuing an exception inside the loop within a begin-end block. I want to redo the current iteration in rescue block, so putting redo will execute the each block again and not the begin block, right?
[17:00:02] AndreYuhai: phaul: Thank you.

2019-04-03

[08:19:50] AndreYuhai: Remote host closed the connection

2019-04-01

[10:38:04] AndreYuhai: has joined #ruby
[10:39:47] AndreYuhai: Hello there, I want to select a range from the array which will be from the index number 1 to the last index. I've tried this: arr[1..] and this worked on irb, but then RuboCop warns me on RubyMine. Is that expression correct?
[10:47:08] AndreYuhai: al2o3-cr: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux]
[10:48:22] AndreYuhai: al2o3-cr: unexpected token trBRACK
[10:54:10] AndreYuhai: al2o3-cr: no I didn't
[10:55:14] AndreYuhai: al2o3-cr: okay I will just a sec.
[11:03:42] AndreYuhai: al2o3-cr: should I create the rubocop.yml file for each project separately? Because I can't find it.
[11:07:03] AndreYuhai: al2o3-cr: No I didn't that's why I do not know about it. :D
[11:10:21] AndreYuhai: al2o3-cr: Thank you. Now I've created them but in rubocop.yml it says inherit from rubocop_todo.yml but in todo there is nothing about AllCops
[11:25:19] AndreYuhai: al2o3-cr: I just added it but the warning is still the same
[11:26:38] AndreYuhai: al2o3-cr: oh sorry I will do that now.
[11:29:52] AndreYuhai: but the one in the project directory will stay too, right?
[11:31:07] AndreYuhai: al2o3-cr: yes in $HOME and project directory
[11:31:23] AndreYuhai: al2o3-cr: now everything is fine but I do not know because of which one :D
[11:31:51] AndreYuhai: al2o3-cr: okay
[11:32:33] AndreYuhai: al2o3-cr: Yes now that is all.
[11:32:41] AndreYuhai: al2o3-cr: and it worked, thank you. :)
[11:34:13] AndreYuhai: al2o3-cr: anyway I appreciate the help ^^
[12:11:51] AndreYuhai: al2o3-cr: Oh I didn't know about that method. Sure that is even better what I needed was just to drop first index (table header :D)
[12:12:48] AndreYuhai: al2o3-cr: Thanks once again! :)
[12:16:48] AndreYuhai: al2o3-cr: No, that is a table from HTML

2019-03-10

[00:27:57] AndreYuhai: Ping timeout: 245 seconds

2019-03-09

[18:24:49] AndreYuhai: has joined #ruby
[19:48:25] AndreYuhai: Hey there, is there any way to open a CSV file and then just fill in the necessary cells? For example the cell at 4th row and 6th column.
[19:48:58] AndreYuhai: So far I have been reading the CSV file and then changing whatever I want and then writing the whole file back.
[19:54:39] AndreYuhai: rindolf: The data to be inserted?
[19:55:45] AndreYuhai: rindolf: if yes, sometimes the cells are empty so it wouldn't be the same size. The cell to be inserted with the new value can be either empty or there may be another value.
[20:20:28] AndreYuhai: rindolf: thanks, I am reading it right now ^^

2019-01-28

[10:27:24] AndreYuhai: has joined #ruby
[10:28:04] AndreYuhai: Hello there, I am using Mechanize and I sometimes get 503 exception. I am rescuing this exception but how can I make it sleep(5) and try again as long as it gets this exception?
[10:28:43] AndreYuhai: I can just sleep and try it again by simply putting agent.get url inside the rescue block but what I want is a loop to do that as long as it gets that code
[10:32:22] AndreYuhai: canton7: thank you, I am searching
[11:46:43] AndreYuhai: Quit: Page closed

2019-01-07

[03:20:52] AndreYuhai: has joined #ruby
[03:22:41] AndreYuhai: Hello how can I write the xPath for this HTML https://paste.ofcode.org/a2egTxG6tEeKP8QFmaT3qJ I want to get the a tag. Is there any other way besides "//section[@class='pv-contact-info__contact-type ci-email']/div/a" ?
[03:22:57] AndreYuhai: I mean any shorter or better way
[03:36:45] AndreYuhai: Quit: Page closed

2018-12-30

[23:06:12] AndreYuhai: has joined #ruby
[23:06:56] AndreYuhai: Hello there anyone knows how I can solve these kind of captchas ? Containing only numbers. https://screenshots.firefox.com/EvV2UpRBTCgSEqjr/hacumre.diyanet.gov.tr
[23:07:14] AndreYuhai: What libraries would help me?
[23:09:42] AndreYuhai: Zarthus: we can say so :) But since there are already bots solving these, I would like to figure that out. :D
[23:09:58] AndreYuhai: catphish: There is a bot doing that but I don't know how
[23:10:24] AndreYuhai: By the way it's just numbers.
[23:12:25] AndreYuhai: Yes that is right. Sorry for that and thank you anyway.

2018-09-20

[07:08:45] AndreYuhai: has joined #ruby
[08:14:27] AndreYuhai: Quit: Page closed

2018-09-19

[19:38:29] AndreYuhai: has joined #ruby
[19:44:21] AndreYuhai: Hi, how can we test stuff on Travis which requires username and password? Any sources?
[19:47:37] AndreYuhai: havenwood: Oh thank you! :) I didn't even know it was called like so.
[23:58:45] AndreYuhai: Ping timeout: 252 seconds

2018-09-14

[13:13:36] AndreYuhai: has joined #ruby
[13:14:36] AndreYuhai: Hello, does an instance object get garbage collected when I assign something else to the same variable which was holding the referred object before? Or how does this works? Any sources?
[13:34:48] AndreYuhai: tbuehlmann: Thank you. ^^ I was wondering whether it would take so much memory because I instantiate an object a lot of times but always assigning it to the same variable.
[13:39:34] AndreYuhai: al2o3-cr: well looks like we don't even need to call it. I guess?
[13:41:57] AndreYuhai: al2o3-cr: Thank you for the example. :)
[14:11:48] AndreYuhai: apeiros: What factors for example?
[14:20:46] AndreYuhai: havenwood: Thanks!
[14:22:49] AndreYuhai: havenwood: I will watch that too. Thank you.
[14:38:14] AndreYuhai: havenwood: Yeap, got it! :)
[15:26:39] AndreYuhai: Ping timeout: 252 seconds

2018-09-13

[11:48:36] AndreYuhai: has joined #ruby
[11:51:17] AndreYuhai: Hi, I have a JSON string from Instagram's page and I've created a class for that. https://dpaste.de/UvYE
[11:51:41] AndreYuhai: But I would like to create an "is_video?" method.
[11:52:11] AndreYuhai: But just on the returned objects from [ ] square brackets
[11:52:36] AndreYuhai: For example: "some_json_obj[1].is_video?" How could I make this work ?
[11:56:18] AndreYuhai: Guess I would have to create a class for edge objects too and then put the method there.
[14:26:02] AndreYuhai: Quit: Page closed

2018-09-09

[22:03:11] AndreYuhai: apeiros: well, what if I wanted to run core.rb directly? Would it work in this situation?
[22:03:46] AndreYuhai: I mean for example just below the code we could create an instance an run a method of that class which also runs that "login" method
[22:05:52] AndreYuhai: apeiros: Now everything is clear. Thank you. :)
[22:14:56] AndreYuhai: Quit: Page closed