#ruby - 19 June 2017
« Back 1 day Forward 1 day »
[00:23:58] geggam: hightower2, my ruby is weak has hell but it looks like that map creates an array correct ?
[01:10:45] geggam: it correlates to the mapping and the sort doesnt lose the index.. so i create a dynamic port mapping for autoscaling ( sort of ) cassandra nodes with stunnel configuratons
[01:11:08] geggam: cassandra isnt autoscaling per se but i have everything ready to do the synchronizing if said db dies
[01:11:52] geggam: now i can drop this on all the application servers and rest assured they are all connecting to the same system
[01:36:42] confused4life: If I have a class C, e.g. String, what is the difference between C.methods and C.instance_methods?
[04:09:08] adrianvalenz_: Hello. Ruby on Rails room is dead right now, mind if I ask a Rails question?
[08:01:04] fullmoonpie: dminuoso, and iwanted to isntall this plugin for it? https://github.com/hinrik/poe-component-irc-plugin-megahal
[09:23:55] justatech: when run this code i get this server.rb:3:in `<main>': undefined method `get' for main:Object (NoMethodError)
[09:24:12] ruby[bot]: justatech: https://gist.github.com - Multiple files, syntax highlighting, even automatically with matching filenames, can be edited
[09:30:33] justatech: i'm testing this code for SSRF vulnerability , i am pretty not introduced to ruby at all
[10:55:56] ljarvis: anyway, Ruby just has all of that stuff in their redmine tracker: https://bugs.ruby-lang.org/
[10:56:12] dragoonis: effectively I'm looking for static analysis tools for ruby, python ..etc to give the team a sense of consistency
[10:57:04] dragoonis: Can someone tell me what the Ruby one is called? or link me to the right place? thanks!
[10:58:02] dragoonis: Respectively - need code sniffers / static analysis tools to check such compliance
[10:58:10] GorillaApe: I have a class called Client. Client class uses two types of connections implemented in different classes(ClassA, ClassB). Which is a clean way to provide some kind of events to client instance? For example when ClassB looses connection I want Client to be notified.
[11:09:57] elomatreb: dragoonis: There is no *official* Ruby style guide, if that's what you were looking for. The most commonly used one is probably https://github.com/bbatsov/ruby-style-guide, which Rubocop follows by default
[11:10:42] dragoonis: elomatreb, thanks! I'm really just looking for the most community adopted one - which rubocop is going with, so that's good
[11:10:47] elomatreb: I don't know, I always break the official ones because they mandate single quotes which are a pain to type on QWERTZ
[12:03:51] snowter: hi there, I'm working on a small project and I'm wondering if it's better to use sinastra instead rails
[12:30:05] _mak: I'm looking for what is the most useful type of documentation to capture the way a software should work
[12:34:51] leah2: ged: hey. for legacy reasons i use bluecloth 1... do you know if anyone implemented fenced code blocks (```) for it?
[12:44:00] workmad3: _mak: depends massively on the size and architecture of the software in question
[13:05:46] type01: An API I am making a request to is giving some details in the HTTP status (a full sentence). I'm looking to parse that but it looks like net/http has no way to access the raw status and instead response.code returns the number 403 only.
[13:11:10] type01: elomatreb oh sorry message says "Forbidden", but there's an entire sentence after that too.
[13:16:15] octomancer: i'd say that the server is pushing it's luck to abuse the reason-phrase like that
[13:26:43] dionysus69: I need help with string manipulation and setting up validation. i need to validate if the number is 9 digit long and that all of the string chars are digits. also I need to verify that first 3 digits are of following combination tel_codes = [514, 551, 555, 557, 558, 559, 568, 570, 571, 574, 577, 591, 592, 593, 595, 596, 597, 598, 599] and I also need to escape string before doing all this, people may enter number as 599-01-10-12 or 593110022 or
[13:28:19] dionysus69: if it is escaped and there are no 9 digits and first 3 digits dont match any of those codes, i need to throw validation error in rails
[13:28:46] dionysus69: if you think I should rather use regex for this, let me know. I am not sure which one is better in terms of performance or other variables
[13:29:15] elomatreb: You can use String#tr to strip everything but numbers first, and then I'd probably check the length and then the first three digits
[13:58:33] Cork: i have a class that has a "method" function, is there a way to call Object#method on this instance or isn't that accessable anymore?
[14:01:43] Cork: ah i suspected that one, and ya i am expecting messy; it is in a test suite so that's ok
[14:11:08] dragoonis: If I wanted to check if a cookbook is correct, kind of like static analysis - what's the tool for this?
[14:11:29] dragoonis: just to make sure the cookbook is passable, and executable (on target server), but I want to check such things are build time on the CI servers
[15:16:54] mikecmpbll: how can i call the superclass's implementation of an overridden method, from another instance method in the subclass
[15:21:49] ljarvis: >> class A; def foo; "foo"; end; end; class B < A; def foo; "bar"; end; def bar; method(:foo).super_method.call; end; end; B.new.bar
[16:03:25] ineb: however, it is part of the language. methods can be treated like blocks , procs, lambdas and therefore can be bind/unbind, passed around and called in whatever context you like
[16:24:49] ivanskie: is it possible to check which platform ruby is running in, and do a require '' based on that?
[16:47:56] ivanskie: speaking of scope... how can I create a logger thing. that is accessible anywhere in the app?
[16:48:37] ivanskie: i already have a support module which has methods available everywhere. but im just scratching my head how can I still be able to do logger.info() or logger.warn().. etc etc
[16:49:47] ivanskie: google doesn't seem to be helping right now or im just not asking the right question
[17:13:02] resnik2: Trying to read a bundle of certs via openssl routines. It seems I'm missing something.
[19:06:11] brent__: I need to right a rspec test for a class method, and however need to stub out what goes on inside that method, whats being called and what variables should be assigned inside the method i'm testing. I can't seem to find any good resource on how to stub out stuff inside the method you are calling
[19:11:23] brent__: https://gist.github.com/brentluna/ae6e70e50a5516395fdd3c835784390d is the method i'm trying to test
[19:12:22] elomatreb: brent__: A common pattern for testing methods like that is extracting the request into a dedicated method, which you can easily stub
[19:14:55] brent__: elomatreb: so move that HTTParty line to a method that i can stub out a repsonse?
[19:16:28] brent__: i'm still not quite sure how to assign that stub of the httparty method when calling the main method
[19:26:57] ineb: i want a class which auto initializes with certain members with certain values. then on initialize there are required parameters and optional parameters which will use the provided default values in that class. i came up with this but i dont know if its a bad idea or if there are simpler solutions https://paste.xinu.at/S4M/
[19:28:21] ineb: i think this could go in a module named 'initializable' or so. so a class can include it and only needs to provide some DEFAULT_OPTS and required parameters.
[19:34:22] elomatreb: ineb: One problems with solutions like that is that they silently ignore invalid (e.g. typoed) params
[19:38:04] elomatreb: Most of the times if you have that many parameters your class is doing too much anyway
[21:13:05] ktreese: Anyone help me on outputting some variables? My end goal is to output the original hostname, and next to it, the modified value. Ideally, I'd really like to line everything up in a column, but if that's asking too much, then just getting the output for each line side by side would be nice
[21:15:33] ljarvis: ktreese: you want String#format / String#% or sprintf. You'll have to best guess the widest hostname, though. Otherwise your best shot is to collect them all and keep track of the longest, then pad out the rest when you print them
[21:28:23] ktreese: ljarvis: I am intrigued by reducing the 2 branches into 1. I'm new to ruby, so what does that mean?
[21:28:53] ljarvis: ktreese: line 5 checks for the presence of some prefixes and then proceeds to remove them in the output, correct?
[21:29:25] ljarvis: ktreese: so, check your 2 regexps. They look almost identical, except for this part, right? "(vgt|dev|test|prod|tst|prd)"
[21:30:25] ktreese: ah -- yes. I'm doing this because some of our legacy hostnames do not have the listed prefixes, thus won't match
[21:30:40] ljarvis: your regexp on line 7 would match the same string the previous regexp would match, and it's much more simple; so I say just keep that one, and remove those prefixes if they exist when you print the output
[21:32:54] ljarvis: yep :-) anyway, if there's more code you need inside those branches, then you'd better leave it, but if it's this simple, then there's no point in multiple branches when the second branch condition is just a slightly simplified version of the first, and the branch body is almost identical
[21:34:04] ktreese: :ljarvis makes sense. I'll consider refactoring. What I'm doing here is building a role fact for Puppet based on the hostname of the machine
[21:35:10] ljarvis: cool. Btw, another suggestion: you can use `File.foreach(filename) do |line|` instead of open + each_line
[21:48:47] ktreese: ljarvis: would removing the prefixes be along the lines of using something like a sed?
[23:04:07] aarwine: I'm trying to track games, the players, and the results of the games. For this I've been trying to learn active record. Do these models look reasonable? https://gist.github.com/arwineap/afb15c4faabd49607f231d2f82d0ca5c
[23:25:08] ruby[bot]: Please join #RubyOnRails for Rails questions. You need to be identified with NickServ, see /msg NickServ HELP