#ruby - 04 April 2019
« Back 1 day Forward 1 day »
[02:38:06] violentE: I don't understand what I'm doing wrong, maybe I shouldn't be writing this in ruby https://bpaste.net/show/fd485244b5c7. The first bit there is a ruby script meant to ping a range of ips. which it does and I've included the output. But then if I run fping (similar to ping) it returns more hosts than the ruby script does. why? I took out wait incase that was a problem. idk just need a sanity check
[02:40:22] adam12: violentE: I'm not sure of your network or configuration, but a 1 count might mean a dropped packet could cause a failure. And some routers have been known to deprioritize ICMP so that could even compound it.
[02:41:35] adam12: violentE: That said, I'm sure this would likely be fine in Ruby, albeit it with some tweaks. Could use something like the parallel gem to run multiple pings in parallel. You could then remove the 1 count and keep a short wait in case a few of the hosts take too long to respond.
[02:44:31] adam12: violentE: Out of curiosity, wha'ts the exit status if you run the ping manually? ping -q -c 3 10.10.10.7 ; echo $?
[02:46:45] violentE: that if $?.exitstatus.zero? was when I was trying to Process.wait pid but I decided against that route
[02:51:33] adam12: violentE: I doubt this is Ruby related. My guess for this specifically is a differing of how the ICMP packet is generated by fping and ping.
[02:57:11] adam12: violentE: me too. what about just manually pinging .7 with no arguments. Timeouts?
[02:59:35] adam12: violentE: Maybe ICMP is blocked on the machine and nmap/fping can use some sort of SYN or fragmented ICMP packet to determine response. Hard to say and likely way offtopic for this channel.
[02:59:42] violentE: but if it doesn't respond to icmp request, I wouldn't be able to get results on a basic nmap scan
[03:02:27] adam12: violentE: Instead of shelling out to ping you might be able to try using the net-ping gem. It's been a while since I used it so can't comment on it, and last I remember ICMP through it was reasonably unsafe due to packet creation. YMMV
[03:02:45] adam12: violentE: But it might get you another datapoint to see if you can figure out whats wrong. But it sounds like ping is broken :)
[03:04:25] violentE: I was kind of hoping to not use any gems, is there anything off the top of your head that wouldn't involve using a gem
[03:05:50] adam12: violentE: you could pair ruby + fping if you really wanted. What's your ultimate goal?
[03:06:32] violentE: yes but the purpose is to build a script in ruby. I feel like thats cheating, the bit of ruby then would be the system() bit
[03:08:34] havenwood: violentE: https://github.com/chernesk/net-ping/blob/master/lib/net/ping/icmp.rb#L91-L95
[03:11:35] adam12: violentE: I'd just shell out to fping instead, but use a single host. You could craft your own packet like havenwood is suggesting, if you feel so inclined.
[14:51:27] rbasak: Hello! Where would be good to post about Ubuntu packages of gems please? I'm an Ubuntu developer and raised something on the Ubuntu developer list. I'd like to connect with the right part of the community on the Ruby side of things. https://lists.ubuntu.com/archives/ubuntu-devel/2019-April/040622.html for details.
[14:51:33] rbasak: For Rails I posted to rubyonrails-talk (awaiting moderation), but the topic also applies to Ruby generally.
[15:36:27] towo: Noobish question here. If I have a class and inherit like `class foo < bar`, is bar's initialize() called?
[15:38:42] phaul: initialize is not a special method, works exactly like any other. The new method on the class first allocates an object then calls initialize on it, with normal method lookup
[15:42:32] towo: phaul: (Beware, I may be wrong on terms here) So is the class foo an instanced bar? https://github.com/rubocop-hq/ruby-style-guide#single-line-classes seems to imply this. For context, I'm trying to extend https://github.com/puppetlabs/puppetlabs-ruby_task_helper/blob/master/files/task_helper.rb to have some common objects already instanced and don't need to do it for every inheriting class
[15:44:00] towo: i.e. class SomethingTask < TaskHelper begin (something) foo = bar.baz(quux) end; and in class SomeSubTask < SomethingTask I can use foo.
[15:44:35] towo: (Yes, I'm learning Ruby with the "welp, learn to swim already, you're in the ocean" approach...)
[15:46:25] phaul: oh. You are trying to define local var in the class definition? Local vars are local. They are lexically bound to the scope they are defined in
[15:48:58] towo: Any common practices on getting some objects (assigned to variables) to be there when making a new class? Or is that just not a thing?
[15:49:35] phaul: it is a thing, but I am sure if I tell you how I will send you down the wrong path
[15:50:37] towo: Fair enough. What should I look up instead? Don't need you to fully lay this out for me, just give me some hints for ze googles. :)
[15:51:21] phaul: do you want the value stored in the variable to be part of an instance of the class? do you want the value to belong to the class itself?
[15:53:18] towo: Hm; in the end, as far as I understand the constructs used, there'll only be my one object anyway; I don't need to reuse the values between instances as there is only one; main point is saving on code, as there will be multiple different sub-classes (which only ever get instantiated once)
[15:54:12] towo: At the front end, there's this tool just calling a ruby file and passing structured json on stdin, so no special magic sauce at any point needed, AFAIK
[15:55:34] phaul: can you use a module instead of the class? and in the module you can get into the singleton class of it and just use instance variables. Let me demonstrate...
[15:57:08] towo: Well, I can do pretty much anything I want, really, since the front end AFAIK just does 'RUBYLIB=some:special:dirs echo $json | ruby $file.rb'
[15:59:49] phaul: &>> module X; class<< self ;attr_accessor :foo; def bar; self.foo * 3; end; end; end; X.foo = 10; p [X.foo, X.bar]
[16:00:42] phaul: so here X has a value foo, you can only have 1 X, so it's already a singleton, and bar on X can access it
[16:06:56] phaul: I phrased this really confusingly: "here X has a value foo" .. read it as here X.foo is defined
[16:06:58] towo: Hmm, still trying to see how I'd implement that... I'd write a module and use the accessors in my common code to set up the object instances I need, so i.e. MyModule.foo = bar.baz(quux); and then I can use another function like MyModule.bar that can use the things defined for foo?
[16:08:15] bougyman: I swore I used something called BigNumber for this before. But I can't find that, either.
[16:13:09] phaul: &>> require 'singleton'; class X; include Singleton ; attr_accessor :foo; def bar; self.foo * 3; end; end; x= X.instance ; x.foo = 10; p [x.foo, x.bar] # towo
[16:17:57] phaul: the difference is that in the former foo lives in the module, which cannot be instantiated, in the latter foo lives in the single instance of the class
[18:00:48] havenwood: 2.4 is now in security maintenance mode - so no more bug fixes. Time to bump to 2.5 or 2.6 if you haven't already!
[18:44:11] sharma: Opportunity to be a Senior Backend Engineer at a VC funded startup. 2-5 yrs exp. and expertise in Ruby On Rails required. https://flow.invidelabs.com/jobPosting/5c80d2cb9e591c8421a92377
[19:16:00] wallace_mu: anyone know what's the correct syntax for alias_method? i am monkey patching a method from a class and that class is under a module, here is the gist https://gist.github.com/warm200/f18f217de1f4a942417d194d4b2b3fb0
[19:16:23] wallace_mu: module ActiveSupport::Cache::Store # Store is actually a class but i don't know the correct way to put it
[23:17:13] riceandbeans: What's the net/http version of curl -s -i -H "Accept: application/json" example.com/routehere
[23:20:07] riceandbeans: https://bin.disroot.org/?7f3da819d3bcf444#p+znpiw8LgyE+45QBj/TStSDf+wSq2FBNuXqJqgH4D8=
[23:34:28] havenwood: riceandbeans: i mean: https://bin.disroot.org/?6499b55a4e60d37c#InZ0lXcOzYosTylsftFsEJhgCwKpHy8aXxuv0fix6Kk=