« Back to channel list

#ruby - 02 April 2017

« Back 1 day Forward 1 day »
[00:00:03] Rodya_: has joined #ruby
[00:01:07] allisio: In that case, `ARGV[2]` will be `nil`, and the same for `$FILE_NAME`. `File.open` expects a String.
[00:12:47] fulcan: has joined #ruby
[00:14:13] nowhere_man: has joined #ruby
[00:33:30] Jameser: has joined #ruby
[00:36:07] charliesome: has joined #ruby
[00:38:00] johnny56: has joined #ruby
[00:44:39] _sfiguser: has joined #ruby
[00:47:33] batmaan: has joined #ruby
[00:49:38] batmaan1: has joined #ruby
[00:52:38] slackR: has joined #ruby
[00:56:14] Xiti: has joined #ruby
[00:57:10] sarbs: has joined #ruby
[00:58:38] Coldblackice: has joined #ruby
[00:59:18] cyphase: has joined #ruby
[01:05:45] charliesome: has joined #ruby
[01:11:27] genpaku: has joined #ruby
[01:11:31] yokel: has joined #ruby
[01:16:34] bkxd: has joined #ruby
[01:20:19] sniffer: has joined #ruby
[01:22:50] bkxd: has joined #ruby
[01:29:58] acalycine: Anybody use Nokogiri?
[01:30:11] allisio: Loads of people use Nokogiri.
[01:31:20] acalycine: I want to fetch the first result (from top to bottom) on the page, atm I'm using #scan.
[01:32:07] allisio: acalycine: http://www.nokogiri.org/tutorials/searching_a_xml_html_document.html#single_results
[01:32:58] acalycine: Right. So line 6 in this: https://gist.github.com/anonymous/b3e6167d8e9a2590bc164b7a0f024982 would have a ".first" at the end of it?
[01:38:34] ThatsNotJack: has joined #ruby
[01:42:45] jdm: has joined #ruby
[01:43:17] allisio: You said you were using Nokogiri.
[01:43:23] allisio: Implied that, anyway.
[01:48:16] agent_white: has joined #ruby
[01:48:57] acalycine: Huh? That is Nokogiri.
[01:50:27] allisio: That's not Nokogiri. That's using regular expressions to parse HTML.
[01:51:11] acalycine: Is there any way to do it using regex then?
[01:52:51] Verity: that got it, ty
[01:53:55] zipace: has joined #ruby
[01:54:22] acalycine: Doesn't the regex already have the nongreedy thing on it? "(.*?)"
[01:55:35] allisio: Yeah, but you're using #scan. Seems like you probably want #match instead.
[01:55:52] allisio: Or even just String#[](Regexp), if you're feeling frisky.
[01:56:15] Verity: is there really any point in even havingb this base class and deriving fro it
[01:56:24] gix: has joined #ruby
[01:56:38] allisio: acalycine: That is, you could say `viewgames[/.../]`, and then $1 would contain the relevant game ID.
[01:58:10] d^sh: has joined #ruby
[01:59:52] acalycine: As the regex?
[02:00:21] johnzorn: has joined #ruby
[02:02:58] Verity: allisio, should I put the SOH, ACK etc inside the class, alsong with the COMMAND = ARGV[1] etc
[02:05:58] libastral: has joined #ruby
[02:06:33] allisio: Verity: If you'll pardon my candor, I think you've picked an awful project for your first foray into Ruby.
[02:06:43] acalycine: Not like `matches = viewgames.match(/.../)[0]`, right? Because that gives "<!D".
[02:07:09] allisio: It's certainly the sort of thing Ruby could be made to do and do well, but it's not a great candidate for a beginner exercise that would serve as a proper on-ramp into the language.
[02:07:41] allisio: It's nasty and low-level and not well-suited to object-orientation.
[02:08:53] KnownSyntax: has joined #ruby
[02:10:33] Verity: I'm making progress though
[02:10:40] Verity: and I'm learning ruby =D
[02:11:18] allisio: Grueling progress, but kudos to you for sticking with it.
[02:12:20] Jameser: has joined #ruby
[02:15:12] acalycine: allisio: I'm still not sure what you mean by `viewgames[/.../]`
[02:15:24] allisio: acalycine: What's unclear?
[02:15:52] houhoulis: has joined #ruby
[02:16:07] chouhoulis: has joined #ruby
[02:16:34] acalycine: How to implement it.
[02:16:41] allisio: Do you know why you're using parentheses in your regex?
[02:16:59] acalycine: To put the actual regex in?
[02:17:59] acalycine: `.scan(Regex)`
[02:19:43] allisio: The parentheses in your regex.
[02:19:49] allisio: Do you know where your regex is?
[02:20:05] acalycine: Between the / /
[02:20:38] acalycine: parentheses split it up into groups like [0] don't they?
[02:20:50] acalycine: capturing groups
[02:24:33] Jameser: has joined #ruby
[02:33:51] allisio: acalycine: Referencing into the results of a #scan with `[0]` will give you the first of potentially many matches, not the contents of a capture group.
[02:34:20] allisio: But yes, parentheses in regexen are for delineating capturing groups, and you only need the one that pulls out the game ID.
[02:34:38] allisio: You can just swap out Line 6 for the one I gave you, and then the game ID will be in the `$1` "pseudo-global" variable.
[02:35:08] agent_white: has joined #ruby
[02:35:27] allisio: You could also do `viewgames ~= /.../` with a named capturing group to automagically introduce a `gameid` local variable, but you probably shouldn't.
[02:35:38] Jameser: has joined #ruby
[02:37:32] acalycine: `matches = viewgames[/.../]` is what you gave me, right?
[02:37:57] acalycine: That, by itself, results in "<!D"
[02:38:17] acalycine: How is it referencing `team`, the user input?
[02:38:49] xall: has joined #ruby
[02:39:27] zel: has joined #ruby
[02:39:40] acalycine: The original line 6 uses `#{team}` to do so.
[02:39:48] Satyajit: has joined #ruby
[02:41:27] allisio: Why do you have or even want a variable called `matches` when your intent is to have just the one?
[02:41:47] allisio: Put your regex in the hole, silly.
[02:44:33] ElSif: has joined #ruby
[02:45:20] acalycine: That's not really that much of an issue though, is it?
[02:45:40] acalycine: How is that regex referencing the `team` variable?
[02:46:40] acalycine: `viewgames[/../][1]` should produce the gameid according to you, I understand.
[02:46:45] swemoney: has joined #ruby
[02:48:20] duderonomy: has joined #ruby
[02:48:54] allisio: That's simply not what I said.
[02:49:16] acalycine: OK, so what are you saying?
[02:50:19] acalycine: https://gist.github.com/anonymous/ac661f46c222316c19e67466d3e3d6ef
[02:50:21] acalycine: That's what I have.
[02:57:08] spicerack: has joined #ruby
[02:58:20] Verity: how can I handle the case of the user entering an invalid filename (file that doesnt exist)
[02:58:24] Verity: with my own error message
[02:58:30] Verity: and a graceful exit
[02:58:57] allisio: has joined #ruby
[02:59:27] allisio: acalycine: https://eval.in/766204
[03:00:31] allisio: &ri File#exists?
[03:00:31] `derpy: No results
[03:00:43] allisio: &ri File.exists?
[03:00:43] `derpy: http://ruby-doc.org/core-2.4.0/File.html#method-c-exists-3F
[03:01:38] allisio: You can use Kernel#warn to conveniently write to stderr, and then just `exit 1` to indicate that your program didn't execute "as expected".
[03:02:21] GodFather: has joined #ruby
[03:02:56] allisio: Probably you're tempted to just try to open whatever the user provides and catch the ENOENT exception, but don't.
[03:03:30] Verity: this exist? method is clean, it works great
[03:03:38] Verity: now I can handle the case of non-existing file
[03:04:34] acalycine: With that code I still get an unexpected result. The game ID I want from the webpage is "1148", but I get "1139" from that.
[03:06:35] acalycine: If you look on the webpage, I want the ID from "Brisbane vs Essendon", rather than "Gold Coast vs Brisbane".
[03:10:10] HoierM: has joined #ruby
[03:11:24] thistle: has joined #ruby
[03:11:47] swemoney: I'm not sure where else to ask this. Does anyone know a way to log in to the amazon developer dashboard (developer.amazon.com) via ruby? I've been playing with Mechanize and Watir for a while without a lot of success. Any time I submit the login form I get redirected back to the login page. I feel like it's a cookie issue.
[03:16:26] armyriad: has joined #ruby
[03:20:25] spicerack: has joined #ruby
[03:22:13] GodFather: has joined #ruby
[03:27:40] Verity: if valid_commands.include? command != true
[03:27:42] Verity: what is wrong with this
[03:28:12] gdonald: has joined #ruby
[03:30:02] madgoat: has joined #ruby
[03:30:28] allisio: Verity: You're being bitten by precedence.
[03:30:34] allisio: The fix for that is always parentheses.
[03:30:56] allisio: It's being parsed as `valid_commands.include?(command != true)`.
[03:31:35] allisio: Just say `if valid_commands.include? command`.
[03:31:57] madgoat: has left #ruby: ()
[03:38:29] GodFather: has joined #ruby
[03:41:04] charliesome: has joined #ruby
[03:42:41] duckpupp1: has joined #ruby
[03:42:48] swemoney: has joined #ruby
[03:42:49] acalycine: allisio: your code doesn't work.
[03:43:03] allisio: acalycine: Use this regex instead: /GameID=(\d+)">[^>]+> #{team}/
[03:43:22] allisio: It's brittle as fuck, but it'll work unless and until they change their HTML slightly.
[03:43:45] acalycine: Shit, thanks. That works.
[03:44:06] allisio: I'm too inebriated to be interested in explaining why it works, but you're welcome.
[03:44:25] segy: has joined #ruby
[03:45:42] kegster: has joined #ruby
[03:48:12] GodFather: has joined #ruby
[03:49:33] allisio: swemoney: It's probably a cookie issue, but try the low-hanging fruit of sending along a sufficiently "real browser"-like User-Agent header.
[03:50:09] swemoney: allisio: thanks. I've tried changing the user agent. sadly, no change.
[03:50:42] allisio: swemoney: What you've usually gotta do in situations like this is "physically" visit the login page, put whatever cookies that nets you in the jar, then send those along with the actual login request.
[03:51:23] chouhoulis: has joined #ruby
[03:51:50] swemoney: allisio I'm looking into checking that now. When I use Mechanize, I get a session_id and session_id_time cookie.. I feel like there should be others that are probably set via javascript or something.
[03:52:10] swemoney: I would think using watir with phantomjs would allow for those javascript cookies, thou
[03:52:36] allisio: swemoney: That may well be so, in which case you'll have to get your hands dirty and look at what all's being sent along with "real" login requests.
[03:53:28] allisio: But yeah, that's the sort of thing PhantomJS is intended to make painless, so :/.
[03:53:36] swemoney: allisio cool.. thanks. I'll keep cracking at it. Was hoping there was a wheel somewhere I didn't have to reinvent. I don't understand why Amazon doesn't have a reporting API for their mobile ads reports.
[03:54:25] allisio: swemoney: A nifty trick is to open your browser's developer console (F12, usually), make the request, right-click it and "Copy as cURL", then figure out exactly how much of the noise you need to send along to pass inspection.
[03:55:45] rakm: has joined #ruby
[04:00:45] gix: has joined #ruby
[04:02:45] antgel: has joined #ruby
[04:06:43] MichaelSmith_: has joined #ruby
[04:06:51] MichaelSmith_: Can we all agree on one thing?
[04:07:25] allisio: Yes, that we can all agree on one thing.
[04:07:29] icyphox: has joined #ruby
[04:08:00] icyphox: system "curl -F 'file=#{strone}' https://0x0.st"
[04:08:07] icyphox: why does this cause a segfault?
[04:08:39] aryaching: has joined #ruby
[04:08:44] allisio: Post the dump.
[04:09:02] icyphox: I'm unpacking an ARGV into a variable called one, and then converting that variable to a string (stored in strone), using to_s
[04:09:21] allisio: We burn people for variable names like that around here.
[04:09:28] allisio: You should go.
[04:09:33] icyphox: allisio: There really isn't any dump. It just says 'Segmentation Fault'.
[04:09:43] icyphox: Hey I'm sorry, I just started Ruby yesterday.
[04:10:04] MichaelSmith_: You don't have set faults in ruby this isn't c
[04:11:01] MichaelSmith_: Segmentation faults don't exist in ruby
[04:11:10] MichaelSmith_: Ruby is a duck typed language
[04:11:17] allisio: That's not quite true.
[04:11:20] MichaelSmith_: It's also object oriented
[04:11:23] allisio: >> require 'fiddle'; Fiddle::Pointer.new(1)[1]
[04:11:24] ruby[bot]: allisio: # => /tmp/execpad-8d7851d90e7c/source-8d7851d90e7c:2: [BUG] Segmentation fault at 0x000002 ...check link for more (https://eval.in/766229)
[04:11:31] icyphox: MichaelSmith_: https://0x0.st/vlH.png
[04:11:35] icyphox: here's a screenshot.
[04:12:20] MichaelSmith_: That's a c thing
[04:12:34] allisio: But ruby[bot] is a Ruby evaluator.
[04:12:54] icyphox: Okay, fine. But why's it showing up? That's all that code I have.
[04:13:19] icyphox: I mean, I don't know what's my mistake here.
[04:13:26] MichaelSmith_: Wait so is ruby like C but for retards?
[04:13:48] MichaelSmith_: Because that would explain everything about segfault
[04:13:53] allisio: You okay, bud?
[04:13:59] allisio: Let's talk about what's on your mind.
[04:14:06] icyphox: Let's not.
[04:14:14] icyphox: Let's talk about why my code's wrong.
[04:14:38] MichaelSmith_: Well, I have lots of stuff on my mind. Like Hitler was wrong about lots of stuff, but he was right about Jews.
[04:14:50] havenwood: !troll MichaelSmith_
[04:14:50] ruby[bot]: +bb MichaelSmith_!*@*$#ruby-banned *!*@gateway/web/freenode/ip.50.140.195.159$#ruby-banned
[04:14:50] ruby[bot]: ruby[bot] kicked MichaelSmith_: is a bannable offense, see http://ruby-community.com/pages/user_rules
[04:15:32] allisio: I considered calling him out from the first, but there was some hope that my answering his trollish question with a paradox would fry his circuitry.
[04:16:08] icyphox: Now that that's out of the way...
[04:16:22] havenwood: icyphox: Gist the contests of test1.rb?
[04:16:31] havenwood: icyphox: gist.github.com
[04:16:37] icyphox: I know lol.
[04:17:17] vali: has joined #ruby
[04:17:21] pytuger: has joined #ruby
[04:18:06] icyphox: https://gist.github.com/icyphox/4f25e700602866882623820e62aaf05a
[04:18:18] havenwood: icyphox: It doesn't answer your question, but Curb and Typhoeus are both very nice Ruby libcurl wrappers.
[04:19:25] xall_: has joined #ruby
[04:23:07] havenwood: icyphox: Alternatively, shell out with Kernel#` (backticks) instead of Kernel#system.
[04:24:32] sebd: has joined #ruby
[04:25:07] raatiniemi: has joined #ruby
[04:25:24] icyphox: havenwood: I don't quite know what that is. Mind ELI5ing?
[04:25:26] ElderFain: has joined #ruby
[04:26:15] twistedpixels_: has joined #ruby
[04:26:20] havenwood: icyphox: Or Ruby ships with net/http, and a net/http wrapper called open-uri that just does simple GET requests that you could use here.
[04:26:36] tjvc: has joined #ruby
[04:26:37] tjvc: has joined #ruby
[04:26:43] havenwood: icyphox: Try both of these is irb/pry:
[04:26:44] icyphox: yeah, I know about that, but that's not what I need here.
[04:26:47] havenwood: system 'ls'
[04:27:43] Phage: has joined #ruby
[04:27:43] Phage: has joined #ruby
[04:27:50] icyphox: running `ls` did something very weird.
[04:28:12] Axy: has joined #ruby
[04:28:19] havenwood: icyphox: Try: puts `ls`
[04:28:35] allisio: I have my suspicions.
[04:28:42] icyphox: Ah, that worked.
[04:28:52] tristanp: has joined #ruby
[04:28:52] Takumo: has joined #ruby
[04:28:52] Takumo: has joined #ruby
[04:29:16] havenwood: icyphox: HTTP.rb is one of many nice HTTP libraries in Ruby. It has a nice API. You can POST a form like: HTTP.post('https://icyphox', form: {foo: 42})
[04:29:20] bronson: has joined #ruby
[04:29:28] havenwood: ACTION icyphox: https://github.com/httprb/http#readme
[04:30:03] icyphox: havenwood: Okay so I tried doing my curl command using the backticks.
[04:30:18] icyphox: It started working fine, and then segfaulted again.
[04:30:19] havenwood: icyphox: no segfault?
[04:30:23] Silthias: has joined #ruby
[04:31:01] icyphox: Is it something wrong with my Ruby version?
[04:31:39] uxp: has joined #ruby
[04:31:51] havenwood: icyphox: For starters: ARGV.to_s #=> "[]"
[04:32:19] havenwood: icyphox: Array#to_s isn't what you're actually wanting.
[04:32:32] Psy-Q: has joined #ruby
[04:32:53] j416: has joined #ruby
[04:33:12] WebDawg: has joined #ruby
[04:33:34] icyphox: havenwood: Oh alright.
[04:35:07] DarthGandalf: has joined #ruby
[04:36:09] artmann_: has joined #ruby
[04:36:33] LiquidInsect: has joined #ruby
[04:36:36] nemesit|znc: has joined #ruby
[04:36:56] rotty_: has joined #ruby
[04:37:06] moufl: has joined #ruby
[04:37:24] Prira: has joined #ruby
[04:37:25] kies: has joined #ruby
[04:38:28] icyphox: havenwood: nope, still gives me a segfault.
[04:42:19] Jameser: has joined #ruby
[04:42:58] havenwood: icyphox: It's not hard to post a form with net/http and uri in the stdlib. Maybe do that instead of shelling out. Your curl command isn't right as you have it.
[04:43:07] havenwood: icyphox: http://www.rubyinside.com/nethttp-cheat-sheet-2940.html
[04:43:36] havenwood: icyphox: see the "POST form request" section
[04:43:44] zacts: has joined #ruby
[04:43:50] pytuger: has joined #ruby
[04:44:11] pytuger: has joined #ruby
[04:45:18] gdonald: has joined #ruby
[04:46:43] havenwood: icyphox: TL;DR: Net::HTTP.post_form URI.parse('http://example.com'), {'q' => 'My query'}
[04:47:49] havenwood: icyphox: https://ruby-doc.org/stdlib-2.4.1/libdoc/net/http/rdoc/Net/HTTP.html#method-c-post_form
[04:48:13] icyphox: Okay, I'll look it up.
[04:49:23] matthewd: FWIW, that looks like it's curl that's segfaulting
[04:52:43] rakm: has joined #ruby
[04:52:52] swemoney: allisio hah. I think I figured it out. I found a javascript call which set an amznTest cookie to test if cookies were enabled. When I set that cookie manually before submitting the login, it appears to go through.
[04:57:31] rakm: has joined #ruby
[04:58:02] Efffe: has joined #ruby
[04:59:14] Efffe: how can i install locally the exact gemfile.lock gems instead of `bundle install` installing the latest of a particular gem (and being out of sync with the rest of team).
[04:59:44] Efffe: docs insinuate `bundle install` goes by whatever gemfile.lock is (unless it hasn't been generated yet)
[05:00:04] Efffe: but after a fresh clone of a project a co-worker is working on, and `bundle install`, gemfile.lock is different.
[05:00:12] govg: has joined #ruby
[05:06:06] matthewd: efffe: `bundle install` will indeed install exactly what's specified in the lockfile. If it's not, you have an old version of bundler (there were some narrow cases where some things would get updated), or something else (some bundler+shell enhancement?) that's getting overly enthusiastic.
[05:06:36] Efffe: hm, maybe it's something on our end
[05:13:04] zipace: has joined #ruby
[05:26:28] d^sh: has joined #ruby
[05:28:46] aryaching: has joined #ruby
[05:33:10] _whitelogger: has joined #ruby
[05:37:29] tubuliferous: has joined #ruby
[05:43:24] duckpupp1: has joined #ruby
[05:50:24] spicerack: has joined #ruby
[06:03:10] _whitelogger: has joined #ruby
[06:07:01] Tau: has joined #ruby
[06:11:39] icyphox: havenwood: Thanks for all the help mate.
[06:11:50] icyphox: But I figured out a way to do it with Python instead :)
[06:12:52] banisterfiend: has joined #ruby
[06:16:42] pytuger: has joined #ruby
[06:17:05] pytuger: has joined #ruby
[06:29:00] ThatsNotJack: has joined #ruby
[06:38:52] hndk: has joined #ruby
[06:46:03] cfec0b8d: has joined #ruby
[06:47:24] unshadow: has joined #ruby
[06:49:12] bkxd: has joined #ruby
[06:50:55] aglorei: has joined #ruby
[06:51:51] shinnya: has joined #ruby
[07:03:06] grh: has joined #ruby
[07:10:16] jgnagy: has joined #ruby
[07:11:16] pulkit4tech: has joined #ruby
[07:13:00] socxon: has joined #ruby
[07:15:45] rippa: has joined #ruby
[07:16:05] frumosa: has joined #ruby
[07:16:30] banisterfiend: has joined #ruby
[07:16:30] frumosa: How can one find RailsVersion by looking at configuration
[07:16:54] frumosa: Like i tried config/boot.rb et
[07:17:01] frumosa: But i am unable to see rails version
[07:17:08] agent_white: has joined #ruby
[07:17:29] matthewd: frumosa: Check the Gemfile / Gemfile.lock
[07:17:56] frumosa: What should be the path of Gemfile or Gemfile.lock , is it inside any sub-directory matthewd
[07:18:35] libastral: has joined #ruby
[07:18:50] matthewd: It's in the root of the application. If it's not there, that suggests the rails version is very old. Head to #rubyonrails and we can try to work it out.
[07:19:44] frumosa: sure matthewd
[07:20:35] frumosa: I got something like gem 'rails', '~> 5.0.2'
[07:20:41] frumosa: so that means my version is 5.0.2
[07:21:51] matthewd: Ah okay, yes, that's current
[07:22:01] frumosa: Latest one cool
[07:24:47] pmunt: has joined #ruby
[07:25:06] atmosx_: has joined #ruby
[07:25:18] atmosx_: has left #ruby: ()
[07:25:36] Toledo: has joined #ruby
[07:27:34] frumosa: What can someone do potentially incase they have secret_token of my rail app
[07:29:10] ddffg: has joined #ruby
[07:30:01] GreySunshine: has joined #ruby
[07:32:38] antgel: has joined #ruby
[07:32:47] GreySunshine: Hello, I tried installing ffi gem and I'm getting this error http://lpaste.net/354193 what should I do?
[07:34:45] djbkd: has joined #ruby
[07:38:26] planigan: has joined #ruby
[07:38:48] matthewd: GreySunshine: Install the missing header files. You seem to be using a system- / OS package manager-provided ruby, so there's probably a separate package that contains the headers.
[07:39:37] matthewd: GreySunshine: General advice is to avoid system ruby in local development environments.. though opinions vary for production deployments
[07:40:24] Pumukel: has joined #ruby
[07:44:27] duckpupp1: has joined #ruby
[07:48:45] doublemalt__: has joined #ruby
[07:50:01] bkxd: has joined #ruby
[07:56:03] dionysus69: has joined #ruby
[07:57:15] toretore: has joined #ruby
[08:02:49] Jameser: has joined #ruby
[08:10:02] kegster: has joined #ruby
[08:11:33] rippa: has joined #ruby
[08:14:57] Qchmqs: has joined #ruby
[08:18:32] johnny56: has joined #ruby
[08:20:32] lucas1: has joined #ruby
[08:24:46] spicerack: has joined #ruby
[08:26:38] chouhoulis: has joined #ruby
[08:31:06] anuxivm: has joined #ruby
[08:34:40] agent_white: Under sane opinion, do not use the system ruby in production.
[08:35:30] agent_white: If so, likely all hope has already been lost and you're just along for the good coffee.
[08:36:25] marr: has joined #ruby
[08:37:34] TomyLobo2: has joined #ruby
[08:37:40] anuxivm: has left #ruby: ()
[08:41:08] tildes: has joined #ruby
[08:45:11] Tau: has joined #ruby
[08:48:43] _sfiguser: has joined #ruby
[08:55:57] cfec0b8d: has joined #ruby
[08:58:13] Jameser: has joined #ruby
[09:03:08] swemoney: has joined #ruby
[09:05:54] snickers: has joined #ruby
[09:21:33] grh: has joined #ruby
[09:26:36] kegster: has joined #ruby
[09:29:32] sarbs: has joined #ruby
[09:32:34] govg: has joined #ruby
[09:35:06] lenwood: has joined #ruby
[09:38:57] gloscombe: has joined #ruby
[09:39:38] Jackneill: has joined #ruby
[09:43:57] darix: matthewd: if you want to be sure that your stuff is working on production and you prefer system ruby there ... i would stick to system ruby in my dev env too.
[09:44:00] darix: but that is just me
[09:45:10] duckpupp1: has joined #ruby
[09:45:20] Jackneill_: has joined #ruby
[09:45:32] maloik: has joined #ruby
[09:47:18] acalycine: has joined #ruby
[09:48:58] bkxd: has joined #ruby
[09:54:10] _whitelogger: has joined #ruby
[10:04:58] lxsameer: has joined #ruby
[10:19:22] doublemalt_: has joined #ruby
[10:34:25] conta: has joined #ruby
[10:34:49] jgt: has joined #ruby
[10:38:29] Jameser: has joined #ruby
[10:38:34] tildes: has joined #ruby
[10:43:00] ddffg: has joined #ruby
[10:43:19] jusa: has joined #ruby
[10:45:11] byte512: has joined #ruby
[10:48:12] gloscombe_: has joined #ruby
[10:48:34] pulkit4tech: has joined #ruby
[10:55:09] sepp2k: has joined #ruby
[10:57:39] fmartingr: has joined #ruby
[11:06:30] danielpclark: has joined #ruby
[11:10:08] ddffg: has joined #ruby
[11:11:17] govg: has joined #ruby
[11:16:20] gdonald: has joined #ruby
[11:33:29] antgel: has joined #ruby
[11:33:45] byte512: has joined #ruby
[11:37:26] yurikoles: has joined #ruby
[11:38:45] yeticry: has joined #ruby
[11:45:53] duckpupp1: has joined #ruby
[11:57:15] Pumukel: has joined #ruby
[11:57:27] charliesome: has joined #ruby
[12:00:38] nowhere_man: has joined #ruby
[12:13:02] jusa: has joined #ruby
[12:23:07] unshadow: has joined #ruby
[12:28:42] rgtk: has joined #ruby
[12:38:33] unshadow: has joined #ruby
[12:42:18] ddffg: has joined #ruby
[12:42:42] Arpanet69: has joined #ruby
[12:43:55] rippa: has joined #ruby
[12:45:00] Rodya_: has joined #ruby
[12:46:33] meshsmith: has joined #ruby
[12:50:39] jrafanie: has joined #ruby
[12:52:23] jcao219: has joined #ruby
[12:54:03] manveru: darix: well, that's exactly right though :)
[13:07:15] xall_: has joined #ruby
[13:10:35] pilne: has joined #ruby
[13:13:21] hndk: has joined #ruby
[13:17:28] grh: has joined #ruby
[13:18:24] Xiti: has joined #ruby
[13:18:31] Pumukel: has joined #ruby
[13:18:53] HoierM: has joined #ruby
[13:19:53] GodFather: has joined #ruby
[13:22:30] gdonald: has joined #ruby
[13:26:50] conta: has joined #ruby
[13:34:05] xall_: has joined #ruby
[13:35:33] SCHAAP137: has joined #ruby
[13:37:54] madgen: has joined #ruby
[13:40:47] govg: has joined #ruby
[13:53:16] gbaptista_: has joined #ruby
[13:56:43] houhoulis: has joined #ruby
[14:04:30] johnzorn: has joined #ruby
[14:16:13] harfangk: has joined #ruby
[14:22:22] jcao219: has joined #ruby
[14:32:16] Rodya_: has joined #ruby
[14:34:19] zipace: has joined #ruby
[14:39:20] qchmqs_: has joined #ruby
[14:39:39] c0mrad3: has joined #ruby
[14:39:40] rgtk: has joined #ruby
[14:44:21] Qchmqs: has joined #ruby
[14:46:16] ThatsNotJack: has joined #ruby
[14:48:39] conta: has joined #ruby
[14:50:56] DLSteve_: has joined #ruby
[14:51:52] GodFather: has joined #ruby
[14:52:07] ltem: has joined #ruby
[15:07:28] electrostat: has joined #ruby
[15:09:18] GodFather: has joined #ruby
[15:11:38] millerti: has joined #ruby
[15:15:16] ziprar: has joined #ruby
[15:23:49] RubyLearner: has joined #ruby
[15:24:51] RubyLearner: Can you tell me the best book for getting to know Ruby completely? I have been following this book , metaprogramming ruby by perrota , it would be a big help
[15:28:07] nixmaniack: has joined #ruby
[15:28:07] nixmaniack: has joined #ruby
[15:28:36] matthewd: RubyLearner: At a certain point, practice is the important part
[15:30:29] scottschecter: has joined #ruby
[15:30:44] RubyLearner: I agree, but I have been coding on Ruby On Rails for around 3 years now, but I want to learn Ruby now.
[15:32:58] elomatreb: If you've been using Rails you were already programming Ruby, just with a lot of additional libraries
[15:33:23] scottschecter: has joined #ruby
[15:33:25] Rodya_: has joined #ruby
[15:33:35] apeiros: RubyLearner: eloquent ruby, ruby under a microscope, why's poignant guide, …
[15:34:57] blackwind_123: has joined #ruby
[15:35:55] RubyLearner: Yes, but when i look at the code in gems, it's pure ruby like singlelton, instance_eval, class_eval, dynamic methods and everything else. <elomatreb>
[15:36:16] allisio: RubyLearner: And Metaprogramming Ruby hasn't been explaining those?
[15:36:24] meshsmith: has joined #ruby
[15:37:10] allisio: That book dives pretty deeply into what all you can get up to in that department, as I recall.
[15:38:11] RubyLearner: <allisio> Yes, it has been, but am i on the right track to learn ruby, that's what i want to ask. Yes, you are right it covers these extensively.
[15:39:52] tildes: has joined #ruby
[15:40:02] allisio: RubyLearner: Most folks recommend Eloquent Ruby for non-beginners that really want to get a feel for the language.
[15:41:21] __Yiota: has joined #ruby
[15:41:49] RubyLearner: Thanks <allisio> , <apeiros>, <elomatreb>
[15:42:54] al2o3-cr: has joined #ruby
[15:42:55] shinnya: has joined #ruby
[15:43:48] m1911: has joined #ruby
[15:44:28] Lord_of_Life: has joined #ruby
[15:45:21] bkxd: has joined #ruby
[15:45:41] m1911: has joined #ruby
[15:46:05] m1911: has joined #ruby
[15:46:32] grh: has joined #ruby
[15:47:24] Rr4sT: has joined #ruby
[15:52:55] minimalism: has joined #ruby
[15:54:48] RubyLearner: has left #ruby: ()
[16:04:04] DoubleMalt: has joined #ruby
[16:05:18] sepp2k: has joined #ruby
[16:07:50] d3d1rty: has joined #ruby
[16:09:17] ggsmid: has joined #ruby
[16:20:30] nowhere_man: has joined #ruby
[16:27:09] spicerack: has joined #ruby
[16:29:26] kegster: has joined #ruby
[16:31:05] bronson_: has joined #ruby
[16:31:40] aglorei: has joined #ruby
[16:33:58] aglorei: has joined #ruby
[16:34:20] Rodya_: has joined #ruby
[16:34:32] allisio: has joined #ruby
[16:34:37] nofxx: has joined #ruby
[16:35:07] DoubleMalt: has joined #ruby
[16:40:26] kegster: has joined #ruby
[16:45:53] optiz0r: has left #ruby: ("Leaving")
[16:49:34] Mia: has joined #ruby
[16:49:34] Mia: has joined #ruby
[16:50:16] gdonald: has joined #ruby
[16:50:36] mazeinmaze_: has joined #ruby
[16:50:57] xall_: has joined #ruby
[16:51:28] _sfiguser: has joined #ruby
[16:53:44] conta: has joined #ruby
[16:54:31] ayonkhan: has joined #ruby
[16:59:08] jrafanie: has joined #ruby
[17:05:24] conta: has joined #ruby
[17:07:22] ayonkhan: has joined #ruby
[17:07:52] rgtk: has joined #ruby
[17:09:57] Jameser: has joined #ruby
[17:12:25] Fernando-Basso: has joined #ruby
[17:20:39] cagmz: has joined #ruby
[17:25:31] spicerack: has joined #ruby
[17:27:53] blackwind_123: has joined #ruby
[17:28:47] hahuang61: has joined #ruby
[17:35:58] grh: has joined #ruby
[17:35:59] nowhere_man: has joined #ruby
[17:36:16] Rodya_: has joined #ruby
[17:37:02] milardovich: has joined #ruby
[17:38:11] singalaut: has joined #ruby
[17:39:06] gloscombe_: has joined #ruby
[17:44:51] mrwn: has joined #ruby
[17:45:46] mrwn: has joined #ruby
[17:49:05] Channel6: has joined #ruby
[17:49:34] duckpupp1: has joined #ruby
[17:49:53] GodFather: has joined #ruby
[17:52:26] xall_: has joined #ruby
[17:54:28] Lord_of_Life: has joined #ruby
[17:55:55] kegster: has joined #ruby
[17:55:58] Lord_of_Life: has joined #ruby
[17:56:09] _aeris_: has joined #ruby
[17:56:12] kegster: has joined #ruby
[17:57:50] blackwind_123: has joined #ruby
[18:00:23] vali: has joined #ruby
[18:01:46] GodFather: has joined #ruby
[18:02:05] johnzorn: has joined #ruby
[18:03:32] P1ro: has joined #ruby
[18:04:23] cfec0b8d: has joined #ruby
[18:06:34] houhoulis: has joined #ruby
[18:11:24] xall_: has joined #ruby
[18:14:18] blackwind_123: has joined #ruby
[18:15:16] ThatsNotJack: has joined #ruby
[18:16:00] kegster: has joined #ruby
[18:17:04] Sammichmaker: has joined #ruby
[18:18:55] kirun: has joined #ruby
[18:19:21] derp10327: has joined #ruby
[18:19:38] derp10327: Back at it again learning ruby once more :)
[18:20:16] derp10327: Unfortunately RubyMine seems to have gotten less "IntelliJ"-esque after updating to 2017.1
[18:23:23] blackwind_123: has joined #ruby
[18:24:28] mustmodify: has joined #ruby
[18:24:55] mustmodify: how do I fix a conflict between rubygems and ruby? rubygems thinks it's using 2.4, which he tried to uninstall, and ruby is 2.3.4
[18:25:10] naprimer_2: has joined #ruby
[18:27:33] ayonkhan_: has joined #ruby
[18:29:40] rgtk: has joined #ruby
[18:32:36] blackwind_123: has joined #ruby
[18:33:34] havenwood: (solution from more discussion on #rubyonrails ^ was installing the missing Bundler gem on Ruby 2.3.4)
[18:36:28] mustmodify: has left #ruby: ()
[18:36:58] Rodya_: has joined #ruby
[18:38:03] bronson: has joined #ruby
[18:49:38] derp10327: Simple question: So in some programming languages (one that comes to mind is Python, so I'll use its syntax for this) it is possible to import modules using aliases via "import foo as bar"
[18:50:25] derp10327: I'm learning ruby through programming challenges, currently I'm doing some from exercism, and the test suite has me slightly confused
[18:50:32] derp10327: I don't want to alter the test framework of course
[18:51:16] derp10327: here's a snippet https://hastebin.com/lacevibehu.rb
[18:52:16] derp10327: On line 6 they refer to a module (I think this is considered a module? or is a class?) as Complement, however the require_relative is a class called RnaTranscription
[18:52:44] derp10327: Or should I refactor my class name (leaving the filename as is) to "Complement" in the code?
[18:52:53] derp10327: What's the ruby way for this?
[18:53:48] wsewolod: has joined #ruby
[18:57:21] apeiros: derp10327: convention is to name the file according to the constant defined in it
[18:57:45] apeiros: (and stuff starting with an uppercase letter are constants - those may reference a class or a module)
[18:58:17] derp10327: apeiros, so the conventions can't be followed without altering the test suite then right?
[18:58:21] apeiros: e.g. Foo::BarBaz should be in foo/barbaz.rb (ruby convention) or foo/bar_baz.rb (rails convention)
[18:58:38] mooser: has joined #ruby
[18:59:02] derp10327: apeiros, i thought it would be foo/bar_baz.rb in ruby too? Damn rubymine is screwing me up everywhere lol
[18:59:07] apeiros: derp10327: I only have your excerpt. if rna_transcription should define Complement, then you're correct, they don't follow the conventions (which is bad and they should be told so)
[18:59:13] matthewd: derp10327: Well, the named file might in turn load a file named complement.rb
[18:59:38] apeiros: derp10327: no, ruby and rails conventions differ there. rails conventions start to become more common in non-rails code too, though.
[18:59:44] apeiros: at least that's my impression
[18:59:44] derp10327: matthewd, right, but I think I can only submit one file per solution
[18:59:59] matthewd: But I think these exercises are designed to be small-scale, such that you'd have a single file defining all the things
[19:00:15] derp10327: apeiros, I'm sure you're right, rubymine hasn't been friendly since I updated to 2017.1 yesterday :/
[19:00:45] matthewd: Yeah, in that case, it seems reasonable enough to name it after the program, rather than an individual constant it defines
[19:01:02] patarr: has joined #ruby
[19:01:13] derp10327: The IntelliSense is faulty, I.E.: a variable containing a string, str, won't give suggestions from the string libraries
[19:01:47] matthewd: *You* know it contains a string..
[19:02:00] centrx: has joined #ruby
[19:02:11] derp10327: even typing: " "I'm a string". " doesn't give suggestions
[19:02:19] centrx: Github says Nokogiri is a parser for "HTML, XML, SAX, and Reader"
[19:02:22] centrx: What is "Reader"?
[19:02:41] matthewd: Ah okay. I'll grant that it could probably figure that one out ;)
[19:04:15] derp10327: matthewd for $199 a year it oughta lol
[19:05:35] jcao219: has joined #ruby
[19:06:11] matthewd: centrx: I believe Reader is a parse API similar to, but different from, SAX
[19:06:21] armando: has joined #ruby
[19:08:07] apeiros: it's funny to mix HTML & XML together with SAX and Reader. the former are the languages it parses, the latter are methods.
[19:08:09] GodFather: has joined #ruby
[19:08:44] dlitvak: has joined #ruby
[19:08:45] Arpanet69: has joined #ruby
[19:08:57] blackwind_123: has joined #ruby
[19:09:00] apeiros: nokogiri parses html and xml, and it provides dom-, sax- and pullparser. it might be that pull parsers are also called reader, not sure. and I'm never sure about the diff between sax & pull.
[19:10:39] Slinky_Pete: has joined #ruby
[19:12:45] P1ro: has joined #ruby
[19:13:33] GodFather: has joined #ruby
[19:17:21] Vile`: has joined #ruby
[19:19:15] GodFather: has joined #ruby
[19:21:25] vali: has joined #ruby
[19:21:33] havenwood: http://guides.rubygems.org/name-your-gem/
[19:23:12] blackwind_123: has joined #ruby
[19:23:46] matthewd: .. and Rails actually breaks that convention by failing to include underscores in its gem names :P
[19:26:31] centrx: matthewd: Thank you
[19:26:33] centrx: apeiros: Thank you
[19:27:34] hndk: has joined #ruby
[19:27:54] gloscombe_: has left #ruby: ()
[19:29:21] gloscombe_: has joined #ruby
[19:30:42] hahuang61: has joined #ruby
[19:31:16] kegster: has joined #ruby
[19:33:30] ayonkhan: has joined #ruby
[19:37:45] Rodya_: has joined #ruby
[19:44:43] blackwind_123: has joined #ruby
[19:46:15] bkxd: has joined #ruby
[19:46:59] mooser: has joined #ruby
[19:48:17] vali: has joined #ruby
[19:48:24] GodFather: has joined #ruby
[19:49:00] patarr: has joined #ruby
[19:49:56] kith: has joined #ruby
[19:51:33] duckpupp1: has joined #ruby
[19:53:18] kegster: has joined #ruby
[19:53:57] wilbert: has joined #ruby
[19:55:09] ayonkhan: has joined #ruby
[19:57:07] kegster: has joined #ruby
[19:58:34] must_modify: has joined #ruby
[19:59:26] gloscombe_: has left #ruby: ()
[19:59:41] must_modify: So now we're working on using ruby-install to get this guy's ruby working on his mac.
[19:59:43] must_modify: https://gist.github.com/anonymous/eab1ef42cef62601ea41128f14d611fa
[19:59:49] ltem: has joined #ruby
[19:59:53] must_modify: WHAT??? Permission denied as root??!!?!?!
[20:00:21] Xeago_: has joined #ruby
[20:03:19] havenwood: must_modify: Hehe, why are you using Homebrew as root?
[20:04:04] derp10327: Okay another simple question that I don't know how to word properly in order to google it: in each test fixture in this test suite, the assertions are written roughly as follows "expected, Squares.new(different integer here in each fixture).square_of_sum"
[20:04:07] must_modify: I told him to `sudo su` to use ruby-install because that's what I thought he was supposed to do.
[20:04:24] derp10327: where is the argument passed in "new()" going?
[20:04:50] havenwood: must_modify: Nope, no need to do that. You can use ruby-install without sudo. It'll install Rubies to ~/.rubies/, which is a nice setup on macOS.
[20:05:24] apeiros: derp10327: new calls initialize with all args + block
[20:05:38] derp10327: apeiros, thank you :)
[20:05:47] havenwood: must_modify: Since Homebrew is a single-user package manager, Homebrew users tend to do a sudo-less install with ruby-install, since you won't be supporting additional users.
[20:05:48] derp10327: so I need an initialize method then right?
[20:06:09] apeiros: Class#new is basically this: class Class; def new(*args, &block); obj = allocate; obj.__send__(:initialize, *args, &block); obj; end; end
[20:06:22] blackwind_123: has joined #ruby
[20:06:23] apeiros: derp10327: if you want to do stuff on new, yes
[20:06:58] apeiros: but you can write classes without initialize.
[20:07:14] ule: has joined #ruby
[20:07:36] must_modify: havenwood: So if his homebrew rubies are messed up, I wonder if this will actually solve our problem. I guess we'll find out.
[20:08:07] havenwood: must_modify: ruby-install plays nice with brew if you just use the Homebrew user: https://github.com/postmodern/ruby-install/blob/master/share/ruby-install/util.sh#L97-L99
[20:08:27] havenwood: must_modify: brew uninstall ruby && ruby-install --latest ruby 2.3 # or whatever version you are using
[20:08:30] apeiros: must_modify: yes, root is no longer able to do everything on macOS
[20:08:54] allisio: It's still funny.
[20:08:54] apeiros: apple apparently doesn't want to allow a couple of ways to shoot your own foot :D
[20:09:12] patarr: has joined #ruby
[20:09:22] allisio: Oh, that? That's "my" Mac.
[20:09:39] havenwood: must_modify: Or you can leave the brew version, it doesn't matter. You can have chruby fall back to brew with `chruby system` and have system Ruby fall back to real system Ruby with `brew unlink ruby`.
[20:11:22] ule: hi guys..
[20:11:54] ule: I'm trying to get the closest values based on a key.. for example:
[20:11:57] ule: [{:name => 'aaa', :foo => 8.1}, {:name => 'bbb', :foo => 9.4}, {:name => 'ccc', :foo => 12}, {:name => 'ddd', :foo=> 15}, {:name => 'eee', :foo => 16.2}]
[20:12:13] nadir: has joined #ruby
[20:12:43] apeiros: ule: are the names unique? if so… why array of hashes and not just a hash directly?
[20:12:44] ule: If I pass 10.2, I want to see the closest above: {:name => 'bbb', :foo => 9.4}
[20:12:47] kjetilho: has left #ruby: ()
[20:12:55] apeiros: ule: Enumerable#min_by
[20:12:58] ule: apeiros: the names are unique
[20:13:13] ule: min_by.. ok I'm checking here!!
[20:14:25] ule: looks like min_by returns 8.1
[20:14:37] ule: but I want the closest to 10, which would be 9.4
[20:15:07] apeiros: ule: what's the code you used in your block?
[20:15:16] ule: foo.min_by {|x| x[:foo] }
[20:15:30] ule: I don't know how to set the 10 over there
[20:15:31] apeiros: yeah, that gives you the item with the smallest value in :foo
[20:16:08] apeiros: so your next step is to figure out a piece of code which gives you an information about how far away from your "needle" (10.2) your :foo value is
[20:16:23] apeiros: and put that piece of code into the block
[20:16:42] ule: make sense
[20:17:27] apeiros: got an idea?
[20:19:10] ule: my_array.reverse.find { |e| e < 10 }
[20:19:17] allisio: No, not that.
[20:19:35] havenwood: ule: Are you looking for the first value that is less than 10?
[20:19:52] allisio: Well, that's not what he originally said, anyway.
[20:20:02] havenwood: ule: I don't think that's what you want.
[20:20:06] ule: but I need to return the hash.. so {:name => ... :foo => 9.4}
[20:20:06] apeiros: ule: how did you figure out that 9.4 is closer to 10.2 than 8.1?
[20:20:37] ule: apeiros: I could use sort and then get the element above using key - 1
[20:20:49] apeiros: you'll run into the same problem with sort
[20:20:49] havenwood: ule: If I give you two numbers, say 5 and 7 or 9 and 3, how can you figure out the difference between the two numbers?
[20:21:02] apeiros: you first have to find the answer to the above question
[20:21:14] apeiros: > how did you figure out that 9.4 is closer to 10.2 than 8.1?
[20:21:18] allisio: >> [5 - 7, 7 - 5, 9 - 3, 3 - 9] # ule
[20:21:19] ruby[bot]: allisio: # => [-2, 2, 6, -6] (https://eval.in/766468)
[20:21:25] allisio: I see a pattern.
[20:21:39] apeiros: too many cooks IMO
[20:21:47] allisio: Who's leaving?
[20:21:52] havenwood: I have to leave!
[20:21:57] havenwood: ACTION tags out
[20:22:28] Simplicity: has left #ruby: ("Leaving")
[20:23:20] allisio: For what it's worth, if someone doesn't know about nofbyhgr inyhr, no amount of guiding them is going to magically get them there.
[20:24:08] apeiros: allisio: sure. one step at a time.
[20:24:21] jcao219: has joined #ruby
[20:24:38] apeiros: I'm never sure about the correct arguments to tr for that one… :'(
[20:24:47] apeiros: (usually still get it at first try, though)
[20:25:31] allisio: Knowing the position of the letters in the alphabet is a nifty party trick.
[20:25:34] allisio: For about eight seconds.
[20:25:41] apeiros: ule: ok, maybe a different question - how close are 9.4 and 10.2?
[20:27:01] apeiros: allisio: I only know vaguely and I'm too lazy to count. so I usually try the one I *think* is the right for the cut-off point and would then try the chars before/after. but since first try was a hit :D
[20:27:15] apeiros: (yes, I know, I could just let ruby do it for me)
[20:27:43] allisio: apeiros: M is 13 and the step(5) is EJOTY.
[20:27:48] allisio: Pretty easy to get around from there.
[20:27:50] apeiros: [*"A".."Z"][ze_value-1]
[20:28:25] allisio: It becomes fairly automatic with surprising rapidity.
[20:28:39] apeiros: I rarely ever need to know alphabet positions?
[20:28:44] allisio: That's not my problem.
[20:29:00] apeiros: you often need them?
[20:32:45] allisio: Constantly. :<
[20:32:56] tildes: has joined #ruby
[20:33:12] apeiros: ule: ok, not sure where you are. I'll be leaving in ~15min.
[20:33:20] apeiros: allisio: interesting. may I ask what for?
[20:33:22] ule: apeiros: im here
[20:33:32] ule: apeiros: sorry.. I'm trying here
[20:33:56] apeiros: I'm pretty sure you'd get there quicker if you'd answer the question :-p
[20:33:59] ule: if I split my hash based on target, then I can use min or max on those slices
[20:34:28] apeiros: and then you have two candidates and still have to figure which one is closer
[20:34:42] mim1k: has joined #ruby
[20:34:43] apeiros: which - again - requires you to find an answer to the above question ;-)
[20:34:54] ule: I actually need the lower and upper values.. because I'm using these values to get a linear interpolation
[20:35:20] cyphase: has joined #ruby
[20:36:58] apeiros: ok, yes, in that case you can partition and min_by/max_by the two resulting arrays based on :foo's value
[20:37:15] ule: lower = foo.select {|x| x[:foo] < 10 }.last
[20:37:22] ule: where foo is my hash
[20:37:25] ule: worked!
[20:37:29] apeiros: coincidence
[20:37:39] ule: => {:name=>"bbb", :foo=>9.4}
[20:37:49] apeiros: reorder your items and it'll return a different result
[20:38:08] allisio: What's wrong with #minmax?
[20:38:23] ule: yeah.. Indeed in this case I need it sorted to work
[20:38:25] Rodya_: has joined #ruby
[20:39:04] apeiros: allisio: I couldn't come up with a solution immediately, so I figured if possible it'd be a "clever" solution and thus probably not the right choice for ule
[20:39:46] apeiros: ule: sorting by :foo first works, yes. and then you can use .first/.last instead of .min_by/.max_by on the partitions.
[20:39:49] allisio: ule: You don't need to sort your input; as has already been said, you need to figure out what sort of predicate to pass to #min_by/#max_by/#minmax.
[20:40:20] patarr: has joined #ruby
[20:40:20] apeiros: ule: note though, min_by/max_by are less computationally expensive than sort_by.
[20:40:32] ule: so basically, in terms of math, I could loop through all rows.. checking the difference from those numbers.. and in the end, return those with lower difference
[20:40:39] allisio: Questions have arisen that I can't politely ask until we've got this sorted out. :/
[20:41:00] allisio: ule: Now, then, how to determine the least difference?
[20:41:00] muelleme_: has joined #ruby
[20:41:34] ule: allisio: getting the first one from a list of differences or the minimum
[20:45:22] ule: lower = [{:name=>"aaa", :foo=>8.1}, {:name=>"bbb", :foo=>9.4}, {:name=>"ccc", :foo=>12}, {:name=>"ddd", :foo=>15}, {:name=>"eee", :foo=>16.2}].sort_by{ |x| x[:foo] }.select {|x| x[:foo] < 10 }.last
[20:45:32] ule: => {:name=>"bbb", :foo=>9.4}
[20:45:36] cyphase: has joined #ruby
[20:46:21] ule: upper = [{:name=>"aaa", :foo=>8.1}, {:name=>"bbb", :foo=>9.4}, {:name=>"ccc", :foo=>12}, {:name=>"ddd", :foo=>15}, {:name=>"eee", :foo=>16.2}].sort_by{ |x| x[:foo] }.select {|x| x[:foo] > 10 }.first
[20:46:24] apeiros: ok, since you worked out a solution and I've to go:
[20:46:25] ule: => {:name=>"ccc", :foo=>12}
[20:46:31] allisio: He hasn't worked out a solution.
[20:46:44] ule: thanks anyways
[20:46:44] allisio: ule: Do you not want 10.3 to be considered closer to 10.2 than 9.4?
[20:47:18] ule: I just need the lower and upper numbers
[20:47:21] apeiros: allisio: hm? looks correct to me? they corrected their question in that they want both, closest upper and lower, not only the closest.
[20:48:05] ule: exactly.. my bad, it's not the closest, its upper and lower
[20:48:29] allisio: ule: If you had a `{:name=>"fff", :foo=>10.3}` in your collection, you'd still want `lower` to be `{:name=>"bbb", :foo=>9.4}`?
[20:48:30] apeiros: needle = 10; lowers, uppers = data.partition { |date| date[:foo] < needle }; lower = lowers.min_by { |date| needle - date[:foo] }; upper = upper.min_by { |date| date[:foo] - needle }
[20:49:04] ule: apeiros: yes
[20:49:11] allisio: ule: Gotcha.
[20:49:16] ule: allisio: yeah
[20:49:18] apeiros: no sorting needed. you could do it in one iteration even, but that's more annoying to code.
[20:49:29] ule: apeiros: much cleaner.. let me understand what you did
[20:50:20] apeiros: and if you're still looking for "closest", a single min_by is sufficient and allisio will certainly get you there
[20:50:36] apeiros: ACTION gotta go, might check again in a couple of minutes and then be off for the night
[20:50:46] allisio: ule: For posterity's sake, this is what I thought you wanted: https://eval.in/766477
[20:50:54] ule: you guys are awesome
[20:52:01] allisio: Er, that #to_a is superfluous, by the way; the real fix was to parenthesize the block parameters and I just forgot to remove it.
[20:54:48] marcdel: has joined #ruby
[20:55:43] marcdel: has joined #ruby
[21:05:24] Mon_Ouie: has joined #ruby
[21:07:54] apeiros: allisio: I actually have a minmax solution for what they want. it's indeed a bit clever.
[21:08:28] apeiros: I'm not entirely convinced it's correct, but: needle = 10; h.minmax_by { |(k,v)| 1.0/(v-needle) } # using your code for h
[21:08:53] milardovich: has joined #ruby
[21:10:06] apeiros: btw., your code lacks a _by (minmax doesn't take a block, but it won't yell at you if you pass it one)
[21:10:41] allisio: apeiros: I'm having trouble determining why you'd say that.
[21:11:03] apeiros: oh, I'm wrong. minmax = minmax_by? interesting…
[21:11:15] armyriad: has joined #ruby
[21:11:36] apeiros: ah, it wants a comparison
[21:11:48] Mon_Ouie: minmax { |a, b| f(a) <=> f(b) } is similar to minmax_by { |a| f(a) }
[21:12:24] allisio: `f(a) - f(b)` is equivalent to `f(a) <=> f(b)` in most cases.
[21:12:27] apeiros: interesting, I forgot that min/max/minmax all take a block like that
[21:13:01] allisio: Well, no, maybe "equivalent" is a little strong, but it generally does The Right Thing.
[21:13:18] BackEndCoder: has joined #ruby
[21:13:39] apeiros: well, seems I was correct about "you want minmax_by instead of minmax", but was wrong about the "doesn't take a block" part :D
[21:14:06] allisio: You've got me trying to figure out where my code would go wrong.
[21:14:55] allisio: Heh, never mind. It's pretty much completely wrong. :<
[21:15:37] allisio: I definitely wanted #minmax_by.
[21:26:36] Channel6: has joined #ruby
[21:30:13] jgt: has joined #ruby
[21:31:49] MyMind: has joined #ruby
[21:31:50] hahuang61: has joined #ruby
[21:34:32] armyriad: has joined #ruby
[21:39:15] Rodya_: has joined #ruby
[21:39:31] mooser: has joined #ruby
[21:39:48] cyphase: has joined #ruby
[21:42:25] pifon: has joined #ruby
[21:44:23] blackwind_123: has joined #ruby
[21:44:41] Xiti: has joined #ruby
[21:45:18] gloscombe_: has joined #ruby
[21:47:00] bkxd: has joined #ruby
[21:52:17] duckpupp1: has joined #ruby
[21:56:04] blackwind_123: has joined #ruby
[22:04:51] cyphase: has joined #ruby
[22:05:05] skweek: has joined #ruby
[22:05:34] Jameser: has joined #ruby
[22:06:03] scorphus: has joined #ruby
[22:08:47] BabyMario: has joined #ruby
[22:09:02] dasher00: has joined #ruby
[22:11:49] BackEndCoder: has joined #ruby
[22:16:49] banisterfiend: has joined #ruby
[22:18:18] marr: has joined #ruby
[22:20:17] Guest96: has joined #ruby
[22:20:17] Slinky_Pete: has joined #ruby
[22:21:39] patarr: has joined #ruby
[22:23:14] roring357: has joined #ruby
[22:27:57] skweek: has joined #ruby
[22:32:31] hahuang61: has joined #ruby
[22:32:51] jgt: has joined #ruby
[22:33:54] millerti: has joined #ruby
[22:35:00] djbkd: has joined #ruby
[22:37:40] milardovich: has joined #ruby
[22:39:58] Rodya_: has joined #ruby
[22:44:48] blackwind_123: has joined #ruby
[22:46:32] mooser: has joined #ruby
[22:46:58] roring357: has joined #ruby
[22:56:31] blackwind_123: has joined #ruby
[23:04:43] Jameser: has joined #ruby
[23:06:05] Slinky_Pete: has joined #ruby
[23:06:48] pjaspers: has joined #ruby
[23:07:34] BTRE: has joined #ruby
[23:08:10] TheMainFrame: has joined #ruby
[23:08:21] blackwind_123: has joined #ruby
[23:14:53] ElFerna: has joined #ruby
[23:17:53] bkxd: has joined #ruby
[23:21:43] sparr: has joined #ruby
[23:23:32] VladGh: has joined #ruby
[23:27:22] blackwind_123: has joined #ruby
[23:28:11] marcdel: has joined #ruby
[23:33:20] hahuang61: has joined #ruby
[23:33:29] blackwind_123: has joined #ruby
[23:37:19] houhoulis: has joined #ruby
[23:38:46] Tau: has joined #ruby
[23:40:31] rgtk: has joined #ruby
[23:46:02] blackwind_123: has joined #ruby
[23:50:37] patarr: has joined #ruby
[23:51:00] BTRE: has joined #ruby
[23:52:29] blackwind_123: has joined #ruby
[23:54:49] marcdel: has joined #ruby
[23:56:08] enterprisey: has joined #ruby
[23:57:14] enterprisey_: has joined #ruby
[23:57:42] charliesome: has joined #ruby
[23:58:12] danielpclark: has joined #ruby