#ruby - 05 June 2018
« Back 1 day Forward 1 day »
[04:52:41] stalactit: anyone know how i can find A::B since constants is empty? is ObjectSpace.each_object(Class) my only hope?
[11:57:13] ruby[bot]: dionysus69: # => undefined method `strptime' for Time:Class (NoMethodError) ...check link for more (https://eval.in/1015240)
[11:57:58] ruby[bot]: dionysus69: # => undefined method `strptime' for Time:Class (NoMethodError) ...check link for more (https://eval.in/1015242)
[12:07:06] NL3limin4t0r: >> require 'time'; Time.strptime("2018-06-04T14:45:11", "%Y-%m-%dT%H:%M:%N")
[12:17:08] apeiros: >> require 'time'; Time.strptime("2018-06-04T14:45:11", "%FT%T") # as a side-note. as said, I'd use Time.iso8601
[13:20:46] siery: Hi! I don't quite get when an variable is of Integer type.. Why is that not an Integer:
[13:24:38] apeiros: it's because == is an equality check. not a test for whether an object is an instance of a class.
[13:34:21] dalitom: Hey guys, noob here lol.....I need some advice. Basically I am trying to write a network discovery script in our lab, something like... discover all active IPs on each VALN and get information from physical gear ( servers and network gear) (MAC, COP capacity, RAM, HDD, etc). I wanted to go with SNMP but it needs to be enabled on all network gear and install agent on servers.
[13:45:20] havenwood: dalitom: My first thought was arp-scan. If you want to capture nearby packets, monitor mode with airmon-ng with airodump-ng.
[13:50:04] dalitom: havenwood: Well that's Backtrack/Kali stuff, I am writing this in Ruby. I got that part where I scan all VLANs and get active IPs with simple nmap. But actual communication with the server I cannot figure out, without installing SNMP agents
[13:54:04] dminuoso: havenwood: https://www.golem.de/news/programmiersprache-vorschau-auf-ruby-2-6-bringt-jit-compiler-1806-134745.html
[15:02:08] cdunklau: i'm kind overwhelmed by all the tutorial choices here https://www.ruby-lang.org/en/documentation/
[15:02:50] cdunklau: i know it's probably a tired question, so sorry in advance: what's the "best" ruby tutorial for experienced programmers?
[15:08:39] z64: cdunklau: i would recommend "learn ruby the hard way" (though mind the dated style choices). if you find that a bit dull, you might try why's poignant guide. ultimately depends on your background / how you learn
[15:11:51] cdunklau: z64: i'm not a fan of zed shaw's style :) i have heard of why's... does it assume some programming experience? my background is primarily python, with bits of php, perl, java, and C#
[15:15:36] NL3limin4t0r: cdunklau: The codecademy for ruby is a pretty good start. The first few steps might be pretty dump if you'll are already an experienced programmer, but it picks up in the letter steps.
[15:22:15] cdunklau: one thing that confused me at first was vagrant's avoidance of parens for method calls. is that the conventional style, or is it more of an opinionated thing
[15:25:19] elomatreb: There are some different style guides, some recommend always leaving them off where they would be optional, some recommend an approach based on semantics
[15:25:36] havenwood: cdunklau: Some folk call avoiding parens unless it breaks the interpreter "Seattle style".
[15:26:03] NL3limin4t0r: cdunklau: If you're questioning some Ruby code style I mostly check it with the ruby-style-guide but you're free to do whatever you want. https://github.com/rubocop-hq/ruby-style-guide
[15:27:35] havenwood: An argument for parens by drbrain: https://gist.github.com/drbrain/5ea7c9389a55c81fd3c1
[15:28:02] havenwood: I do like how omitting parens often aligns with what's lovely to have on one line.
[15:29:02] havenwood: I like that style a lot. I think omitting them makes it way easier to read. I have less trouble quickly parsing default precedence than trying to follow a bunch of ((..)..)
[15:29:35] havenwood: "When I read code that requires parentheses I eventually stop paying attention to them and treat them like whitespace."
[15:31:11] derp10327: So I was attempting a fairly simple Ruby coding challenge that was just a cliché interview question: https://i.imgur.com/xO74vXu.png
[15:31:56] derp10327: Only problem was that I found out that the scales object wasn't actually an array, but it's own class, once I'd written all of the code to solve the problem.
[15:32:42] derp10327: https://screenshotscdn.firefoxusercontent.com/images/75292408-3a4a-4b11-ba8b-8f3fe945e823.png my "solution"
[16:14:00] baweaver: Also problem of the week is out: https://twitter.com/keystonelemur/status/1003701123092393984
[18:10:31] Jiaoyin: ..so I created a class called "Piglet". I added a def to it called "speak". Inside of speak I have "puts "oink oink!". After that I closed the def and the class.
[18:14:55] elomatreb: You created an instance method. You can now call it on an instance of the Piglet class (created using Piglet.new)
[18:16:39] elomatreb: Indeed, that is the location of the instance (an object) you just created in memory
[18:17:08] elomatreb: A class is like the blueprint for something, and you follow the instructions on it and build what it is for by calling .new on it (in Ruby)
[18:17:48] elomatreb: You don't have to retrieve it from memory, Ruby does that for you. Ruby just doesn't know how to print a Piglet, so it falls back to telling you where it is, basically
[18:18:58] elomatreb: There is nothing meaningful to print for now. You can try calling Piglet.new.speak
[18:20:04] Jiaoyin: I see. That answers my question on how to puts it on screen, but what do you mean by it's nothing meaning to print for now?
[18:20:53] elomatreb: Ruby has to know how to print something. Internally, your piglet is a data structure somewhere in memory, a whole bunch of more or less meaningless bytes
[18:21:21] elomatreb: Some of these bytes are for remembering that it is a Piglet, some of them are for tracking relationships to other objects, and some of them are the actual "data"
[18:22:04] elomatreb: If you don't define some code that tells Ruby what is interesting about it, it doesn't which of these bytes you really care about (i.e. a String is something different from an Array is something different from a Piglet)
[18:22:52] Jiaoyin: makes sense. So, how does someone add another string to it......interger or something else to Piglet.speak
[18:24:03] elomatreb: Now we're back to the class-instance thing. You aren't calling speak on Piglet, but on an instance of the Piglet class
[18:25:17] Jiaoyin: Lets say I want to just add a new string of text to what I have previous. How do I do that?
[18:25:49] elomatreb: You can just open the class and the method definition again, the new method will override the old one
[18:28:04] elomatreb: I suggest you find a Ruby tutorial/guide that starts with class basics, this is something fundamental you need to understand before anything else will make sense
[18:29:54] Jiaoyin: yea, I know. That's what I'm doing right now. Taking a course. But I needed some help to sort things out, that's why I came here.
[18:31:01] Jiaoyin: I just have another question..... how come puts Piglet.new.speak + "Hello" doesn't work? is there a better way of writing this?
[18:34:30] tobiasvl: Jiaoyin: you should show your code, and explain what "doesn't work", ie. give a good description of the error and what you expect to happen
[18:37:06] tobiasvl: OK, so your speak method does not return anything. when you do `puts Piglet.new.speak + "Hello"` you're saying "print out the return value of Piglet.new.speak and concatenate 'Hello' to it" but there is no reurn value.
[18:39:52] tobiasvl: when you do `puts Piglet.new.speak` you're saying "call Piglet.new.speak, and print out the return value afterwards". there is no return value. however, when calling Piglet.new.speak, that method itself prints out something
[18:41:03] tobiasvl: Piglet.new.speak returns nil (as you can probably see in irb), because puts itself returns nil. nil basically means "no return value". if you `puts nil`, you just print an empty line (and return nil again).
[18:41:24] tobiasvl: Jiaoyin: if you want to change the speak method to return the string, you must return it using the return keyword
[18:42:04] tobiasvl: do you know any other languages? ruby does it similarly to other languages, except that it also returns the value of the last expression if there's no explicit return statement
[18:43:20] Jiaoyin: I know a bit of python, but honestly I'm new to that as well so that doesn't count. Ruby is the first lanuage i'm actually trying to learn here.
[18:44:48] tobiasvl: ok, well, python is similar in that print() (the equivalent to puts) returns None (the equivalent to nil)
[19:23:36] cek: What's the link to docs on latest yaml hooks framework? https://ruby-doc.org/stdlib-2.5.1/libdoc/yaml/rdoc/YAML.html is useless.
[21:34:37] siery: Sorry, but I have to enter 9 lines of code to explain my problem. I been trying this on gamedev forum, but nobady answer, so maybe here I will have luck.
[21:36:31] siery: So.. is there something wrong with above code? It seem to produce correct data, but after I wite this into my `Map` constructor the `Map` render stoped working :c
[21:38:17] apeiros: the slice you're showing looks fine. the things I'd change are unlikely to be related to your problem.
[21:39:33] apeiros: ah, `map(&:first).with_index` is probably wrong. by "stops working", do you mean you get an exception?
[21:41:27] siery: Not really, I'm getting the error: undefined method `draw' for nil:NilClass (NoMethodError)
[21:42:31] apeiros: for future reference, "does not work" is a terrible problem description. in case of an exception, the exception is already a much better description.
[21:42:49] apeiros: anyway, "draw" is not called in the code above. so the piece you showed is insufficient.
[21:46:35] siery: The draw method is fair simple.. The part of code above shold feel @tiles instant 2D array with Tile objects.. and this seem to work, here is the state of @tiles[[0, 0]] inside Map.draw, bofore I call Tile.draw
[21:48:04] apeiros: what does this error tell you "undefined method `draw' for nil:NilClass (NoMethodError)"?
[21:54:22] siery: Simply as you see the Tile object calls it't instance of @spirite.draw with work really basic as well, thanks to gosu: https://paste.debian.net/1028126/
[21:59:00] siery: But I guess thats all data I get.. I spend few hours trying to fix that problem, but I guess I need to learn writing tests in Ruby to be more effective. So, thats really weird, I am getting the correct data when checking that object with pry, but the draw function is undefined.. I can't get it.
[22:00:25] apeiros: what does this error tell you "undefined method `draw' for nil:NilClass (NoMethodError)"?
[22:02:55] siery: well.. It looks like this method is not defined in this class? nil:NilClass.. like that class is not existing... idk. But it is defined right bellow constructor
[22:03:34] apeiros: the error tells you that you're trying to call draw on nil (an instance of NilClass)
[22:03:59] apeiros: you should also have gotten additional information with the exception, that is, in which line this happens
[22:05:00] siery: but as I say it calls the instance of Tile with state I posted here: https://paste.debian.net/1028123/
[22:06:41] apeiros: change your code to https://gist.github.com/apeiros/5571a69fc5065e2fec4e0582b611c670
[22:07:18] apeiros: poke around. I'm sure you'll figure out what's gone wrong. if not, ping me. also make sure you read what I wrote ~20min ago ;-)
[22:09:58] rodd: nvm just found my answer here https://relishapp.com/rspec/rspec-expectations/docs/custom-matchers/define-a-matcher-supporting-block-expectations
[22:13:51] siery: ah.. you are right apeiros C:.. but why is x and y still having the value last from the constructor? I didn't declare them as instant variables with @ but as locals.
[22:16:14] siery: becouse y is 11 and x 0, the samme values as at the end of that loop where I feed data from file into RAM
[22:20:31] apeiros: if you changed the code the way I told you, you're not breaking out before iterating
[22:22:43] siery: it is 11 at the end of the constructor becouse it reads an `/n` character, but not saving it to the @height
[22:22:53] apeiros: 23:50 apeiros: note: 0..x will is an off-by-one error. if x = 10, you'll iterate 11 times.
[22:28:53] siery: ah.. ya, good to see that being rendered correctly, now I can go back to making graphics ^_^
[22:36:27] apeiros: it's not as bad as I originally thought, but the way your `if char != ?\n and char.to_s != ' '` works, you can up with @tiles being incomplete.
[22:45:39] apeiros: btw., an alternative take: https://gist.github.com/apeiros/5571a69fc5065e2fec4e0582b611c670 - though personally I tend to use a single position index and calculate x/y from that if necessary. allows you to just do @tiles.each(&:draw)
[22:47:59] apeiros: (and usually you'll only need methods à la each_tile, each_tile_in_col, each_tile_in_row, which are trivial on top of position)
[22:48:56] Spiker01: Hi all. My question on Jekyll static site generator https://stackoverflow.com/questions/50709412/how-to-install-the-required-version-of-packages-jekyll-plugins-in-the-bundle-m
[22:50:43] siery: ya.. I know `if char != ?\n and char.to_s != ' '` can leave some empty space with will be converted to 0, but I guess it is best in my situation, cose tiles with 0 code will be generated all around the map in camera field
[22:54:53] siery: Any ways.. removing this statement will not change any thing in functionality as `c = '\n'.to_i` and `c = ' '.to_i` is 0 as well, and I will spare some if
[23:14:23] akem: I have an issue with UTF-8, when printing it in the cygwin terminal window the string is ok and .encoding reports utf-8, but when i write it to a file using "w:utf-8", then opening the file in notepad++ it shows scrambled characters in place of accents and says encoding OEM-US. :/
[23:17:13] havenwood: akem: If you can, you might consider WSL instead of Cygwin, and Atom instead of Notepad++.
[23:17:49] havenwood: akem: Windows Subsystem for Linux is far from perfect, but I think already more pleasant than Cygwin.
[23:18:18] havenwood: akem: Can you try another text editor to see if the problem is on Cygwin's side?
[23:22:18] akaiiro: @spiker If all the gems installed without errors, start the server with `bundle exec jekyll serve -w`
[23:23:47] akaiiro: Spiker01 If all the gems installed without errors, start the server with `bundle exec jekyll serve -w`
[23:24:09] elomatreb: akem: Keep in mind that encoding detection is very hard, it might just be a heuristic going wrong
[23:28:32] Spiker01: Deprecation: The 'gems' configuration option has been renamed to 'plugins'. Please update your config file accordingly.
[23:33:52] Spiker01: Deprecation: The 'gems' configuration option has been renamed to 'plugins'. Please update your config file accordingly.
[23:33:59] Spiker01: GitHub Metadata: No GitHub API authentication could be found. Some fields may be missing or have incorrect data.
[23:34:08] Spiker01: Liquid Exception: No repo name found. Specify using PAGES_REPO_NWO environment variables, 'repository' in your configuration, or set up an 'origin' git remote pointing to your github.com repository. in atom.xml
[23:34:15] Spiker01: No repo name found. Specify using PAGES_REPO_NWO environment variables, 'repository' in your configuration, or set up an 'origin' git remote pointing to your github.com repository./// But I do not want to use the Git repository for hosting, I want to use it locally.
[23:34:29] ruby[bot]: https://gist.github.com - Multiple files, syntax highlighting, even automatically with matching filenames, can be edited
[23:39:00] akem: havenwood, wow atom setup is 145 Mb, it must be more than just a texteditor, i mean notepad++ is already full featured and is less than 10 Mb.
[23:40:32] elomatreb: It is more than a text editor, it's an Electron app so it ships a complete copy of Chromium
[23:41:13] havenwood: akem: They're starting to optimize for stuff like startup time and typing latency instead of file size: https://blog.atom.io/2018/01/10/the-state-of-atoms-performance.html
[23:43:15] Spiker01: I can not understand in which file do I need to disable the Git profile support?
[23:52:03] Spiker01: English is not my native language. I can not understand what the program is writing to the console. Which file is edited to disable the support for the repositories? I do not understand the big and complex text.