Activity Graph

Page 1 of 2 | Next »


[19:33:40] Karunamon: has joined #RubyOnRails
[19:35:32] Karunamon: Heya folks. Having a really hard time googling this: When doing before/after callbacks on a model using 'has_and_belongs_to_many', which model gets passed into the function you define? The one you're defining the function in, or the one on the other side of that relation?


[15:40:05] Karunamon: Ping timeout: 240 seconds


[17:46:39] Karunamon: Ping timeout: 248 seconds


[20:08:20] Karunamon: has joined #ruby


[00:15:14] Karunamon: Quit: Later!


[09:50:37] Karunamon: has joined #ruby


[11:25:39] Karunamon: Quit: Later!
[11:26:49] Karunamon: has joined #ruby


[01:24:17] Karunamon: Ping timeout: 255 seconds
[01:27:56] Karunamon: has joined #ruby
[16:32:06] Karunamon: Ping timeout: 252 seconds
[16:32:55] Karunamon: has joined #ruby


[01:30:20] Karunamon: has joined #ruby


[15:56:52] Karunamon: Remote host closed the connection


[20:43:06] Karunamon: Ping timeout: 240 seconds


[15:18:25] Karunamon: Quit: Later!
[17:53:04] Karunamon: has joined #ruby


[15:10:46] Karunamon: Ping timeout: 244 seconds


[12:17:03] Karunamon: Ping timeout: 240 seconds
[12:21:46] Karunamon: has joined #ruby


[08:44:03] Karunamon: has joined #ruby


[23:12:56] Karunamon: *.net *.split


[01:32:04] Karunamon: Ping timeout: 240 seconds
[01:33:18] Karunamon: has joined #ruby


[17:42:28] Karunamon: Ping timeout: 264 seconds
[17:44:45] Karunamon: has joined #ruby
[19:42:24] Karunamon: *.net *.split
[19:51:40] Karunamon: has joined #ruby


[11:06:12] Karunamon: Ping timeout: 260 seconds


[19:48:30] Karunamon: *.net *.split
[20:02:10] Karunamon: has joined #ruby


[17:53:48] Karunamon: Max SendQ exceeded
[17:53:55] Karunamon: has joined #ruby


[16:55:15] Karunamon: has joined #ruby
[22:15:30] Karunamon: Excess Flood
[22:15:43] Karunamon: has joined #ruby


[02:02:55] Karunamon: has left #ruby: ("WeeChat 0.4.2")


[21:15:50] Karunamon: Ping timeout: 244 seconds
[21:22:53] Karunamon: has joined #ruby


[22:24:03] Karunamon: Ping timeout: 252 seconds
[22:30:44] Karunamon: has joined #ruby


[20:21:03] Karunamon: *.net *.split


[23:33:35] Karunamon: has joined #ruby


[18:22:05] Karunamon: *.net *.split


[09:50:27] Karunamon: *.net *.split


[15:36:53] Karunamon: *.net *.split
[15:41:37] Karunamon: has joined #ruby
[15:53:05] Karunamon: *.net *.split
[16:47:52] Karunamon: has joined #ruby


[16:20:34] Karunamon: Ping timeout: 260 seconds
[16:26:08] Karunamon: has joined #ruby
[19:30:30] Karunamon: Ping timeout: 260 seconds
[19:35:35] Karunamon: has joined #ruby


[11:14:47] Karunamon: Ping timeout: 260 seconds
[11:15:39] Karunamon: has joined #ruby
[13:38:02] Karunamon: Ping timeout: 259 seconds
[15:37:41] Karunamon: has joined #ruby
[18:39:58] Karunamon: Ping timeout: 260 seconds
[18:46:44] Karunamon: has joined #ruby
[21:50:34] Karunamon: Ping timeout: 245 seconds
[21:51:51] Karunamon: has joined #ruby


[08:31:58] Karunamon: Ping timeout: 272 seconds
[08:39:23] Karunamon: has joined #ruby


[03:45:52] Karunamon: *.net *.split


[00:06:47] Karunamon: Ping timeout: 264 seconds
[00:18:02] Karunamon: has joined #ruby


[06:27:30] Karunamon: Ping timeout: 240 seconds
[06:27:38] Karunamon: has joined #ruby
[23:06:49] Karunamon: *.net *.split


[02:09:49] Karunamon: has joined #ruby


[17:52:31] Karunamon: Quit: ZNC - http://znc.in


[16:50:13] Karunamon: *.net *.split


[20:37:05] Karunamon: I did not know array.new accepted a block
[20:45:50] Karunamon: am I right in understanding that, generally, if you're repeating yourself, you're probably doing something either the wrong way or harder than it ought to be?


[21:31:10] Karunamon: Ping timeout: 255 seconds


[14:24:05] Karunamon: Hiya folks - Just wondering if anyone has any experience invoking Rspec mid-program
[14:26:07] Karunamon: i'm writing a virtual machine management tool, and I'm using rspec to check the data provided by the user to create a machine beacuse the syntax is really simple.. problem is I have to jump through some silly hoops to make this process work (writing an external file which loads a couple of gems and contains the object i'm testing). Ideally I could just run rspec mid-program and check the status of the tests afterwards
[14:38:54] Karunamon: I'm also wondering what the best way to write a function that checks the state of a string against some external tools. I'd like to be able to write 'something'.is_a_foo?, but extending String feels wrong
[15:09:23] Karunamon: man I can't wait for libressl to seriously take off :(
[15:16:40] Karunamon: DeBot: Openssl::
[15:17:00] Karunamon: speak of the devl
[15:18:58] Karunamon: If it's not one of those, that method name is awful
[15:19:02] Karunamon: then again, this is openssl we're talking about
[15:31:30] Karunamon: ooh, basic question now that i'm thinking about it again -
[15:31:46] Karunamon: what's the way to play with the class signature you get back when messing around in irb?


[05:51:25] Karunamon: Google's oauth implementation is a huge pain in the ass.
[05:51:26] Karunamon: that is all.
[05:54:25] Karunamon: we've gone from basic encrypted username/password to expiring token BS
[06:21:01] Karunamon: anyone familiar enough with the google drive gem that knows what exception gets raised when you try to do something with an expired token? otherwise I'm going to have to wait an hour for this one to expire so I can find out :P
[17:05:56] Karunamon: hm, so if you define an exception handler outside a bunch of functions (say they can all throw the same kind of failure you want to deal with), will a 'retry' inside that handler cause the original function to be called again?
[17:07:55] Karunamon: d'oh, getting my terminology mixed up again
[17:07:56] Karunamon: but yes, raise
[17:08:25] Karunamon: say, some kind of API authorization error that requires a reauth, at which point the code that raised the exception needs to try again
[17:08:52] Karunamon: eh, mostly I just want to know if I'm going to have to write one rescue block or 5
[17:12:36] Karunamon: apeiros_: example here - https://gist.github.com/anonymous/d67cb717321cf3a0eca7
[17:21:27] Karunamon: pontiki: if I understand this correctly, the exception would happen in the "do_stuff_with_api" function. It's not handled there, so it bubbles up one level, at which point it's rescued by the block defined above
[17:23:02] Karunamon: any number of API calls could fail with an auth error (FYVM Google...), and that should be handled by re-authing and re-running the function that raised the exception in the first place
[17:24:05] Karunamon: me either :P
[17:26:09] Karunamon: Well, my class is just a plugin container, basically. (Not sure if you're familiar with Cinch, it looks something like this: https://github.com/cinchrb/cinch#plugins)
[17:26:32] Karunamon: I never actually instantiate the class myself, it's done by this library,
[17:27:24] Karunamon: yes, absolutely
[17:28:53] Karunamon: so where are exceptions handled, at the class level, at the method level, or both?
[17:29:49] Karunamon: the function?
[17:30:28] Karunamon: which will happen when the library instantiates my class
[17:30:33] Karunamon: via initilization
[17:30:45] Karunamon: so that instance of the class now has an API session bound to it
[17:31:09] Karunamon: unless my API token got revoked or something
[17:31:15] Karunamon: which shouldn't happen, but I need to deal with it if it does
[17:32:21] Karunamon: the moment you create a new instance of the class
[17:32:53] Karunamon: ACTION is doing the same
[17:36:33] Karunamon: I don't understand this explanation.. class Foo; bar = 1; end. bar=1 gets evaluated and "exists" even though Foo hasn't been instantiated yte?
[17:38:02] Karunamon: so a = Foo.new, then it doesn't happen
[17:38:09] Karunamon: since we've already evaluated defining the class
[17:38:17] Karunamon: instantiating it only cares about what happens in initialize
[17:39:45] Karunamon: ok, that makes sense
[18:02:01] Karunamon: anyways, thanks, I think I got it. We'll see what happens when the token expires in an hour..
[23:27:40] Karunamon: Ok, I need to run this idea by somebody
[23:27:56] Karunamon: i'm hitting a metacritic API that doesn't give me access to the aggregate user score
[23:28:07] Karunamon: but it does say how many of each positive/mixed/negative reviews there are
[23:28:57] Karunamon: Each review is 1-100, so if I were to say mutliply the number of + reviews by 100, middling reviews by 50, and negative reviews by zero, sum that number up, and divide by the number of reviews
[23:30:01] Karunamon: would I have something resembling a reasonably accurate 0-10 rating of whatever title? I tried it a couple of times and it only ended up being off by .1-.2 from what the site actually says, just wondering if there are any edge cases i'm missing


[21:58:52] Karunamon: is anyone familiar enough with testing frameworks to answer some newbie questions? I'm trying to do a unit test for a few functions in a pure console app, and I'm not sure how to instantiate a class that my function depends on
[21:59:24] Karunamon: since instantiating it does a great deal of setup nonsense (connecting to a server and whatnot)
[22:00:00] Karunamon: I can't just define a 'fake' version of the class, since there are a handful of functions mixed into the class I'm actually writing the tests for


[22:44:31] Karunamon: Hi folks - a temporary brain fart prevents me from writing this better, but how would I best DRY this one liner up?
[22:44:42] Karunamon: msg.split(';').length > 1 ? split = msg.split(';')[0] : split = nil
[22:46:10] Karunamon: this looks like it would be a great place for a conditional assignment
[22:52:09] Karunamon: I guess I could do: split = msg.split(';').reverse[1] || nil
[22:52:15] Karunamon: no idea why that wasn't coming to me earlier
[22:52:16] Karunamon: ACTION shrugs
[22:55:24] Karunamon: havenwood: what this is doing is breaking down an incoming command into component parts
[23:01:44] Karunamon: dunno why i'm being so damn evasive, habit of company work i think
[23:01:48] Karunamon: it's a dice roller
[23:01:55] Karunamon: commands look something like
[23:02:25] Karunamon: (repeat value, optional);(dice specification - (number)d(number))(math value, optional)
[23:02:41] Karunamon: 1d20 does the obvious. 1d20+5 does the obvious
[23:03:06] Karunamon: 8;1d20+5 would do eight rolls of d20 with 5 added
[23:04:11] Karunamon: and 8; 4d20+5 would do eight rolls of the sum of 4d20 + 5
[23:08:20] Karunamon: maybe instead of all this post processing I should just write a regex and use .named_capture
[23:09:17] Karunamon: i've got it up to the math bit
[23:11:33] Karunamon: ACTION slow claps
[23:18:30] Karunamon: apeiros_: thanks much. slight mod to allow for multiply, divide, and math arguments of arbitrary length:
[23:18:34] Karunamon: ^(?:(?<rolls>\d+);\s*)?(?<dice>\d+)d(?<sides>\d+)(?<alter>([+-\/*]\d+)*)?
[23:35:53] Karunamon: Say, is there a clever way to have MatchData return nil on an invalid name rather than throwing IndexError?
[23:36:36] Karunamon: ericwood: was that at me or jrhe?
[23:37:34] Karunamon: ah.. see if this was a hash, I could do things like " if matchdata['value_that_may_or_may_not_exist'] "
[23:39:13] Karunamon: basically MatchData quacks like a hash in every way but this so it's a bit jarring


[18:13:16] Karunamon: Has anyone ever written a somewhat complex program in procedural style and then realized after a few weeks that it's becoming a pain to work on?


[14:24:22] Karunamon: Hi folks - what is the correct way to specify the route I want to use when using a _path argument to "link_to"?
[14:25:27] Karunamon: routes contains resources :foo, so I should be able to do "link_to 'New foo', foo_path, action: new", and that should present the view in foo.html.erb - problem is i'm getting redirected to foo's index
[14:28:11] Karunamon: tbuehlmann: a-ha! okay, what controls the existence of those methods? is it just the stuff in routes.rb?
[14:28:58] Karunamon: resources :cartoon_foxes -> new_cartoon_foxes_path etc
[14:29:44] Karunamon: singularized version of what's in routes
[14:38:53] Karunamon: I've used vagrant on something like that for a training class at my company, joelbrewer, it worked pretty well
[14:39:11] Karunamon: it's very easy to learn as well
[14:55:30] Karunamon: hmm, so if i understand the process correctly, /something/new should contain the form where the user enters in the info, and that form posts to /something/create?
[15:00:27] Karunamon: i'm using the bootstrap_form gem and it really wants to do the post to the /new method, which doesn't exist. their syntax always takes an instance var as an argument (name as the resource), but since i'm creating a new thing, that var is nil and breaks the form
[15:03:35] Karunamon: workmad3: ah, that's correct, i was looking at the wrong field in the routes output
[15:04:31] Karunamon: so i'm just using that object to give form_for what it wants, I still have to do, example, Post.new(name: param[:name]).save in the controller?
[15:05:23] Karunamon: *in the controller's create method, that is
[15:07:59] Karunamon: .. Post.create, rather. I'm thinking I should go home today :P
[15:27:13] Karunamon: Actually, speaking of rails and databases
[15:27:30] Karunamon: how exactly do you refer to the record that you're validating against inside of a validator method in your model?
[15:28:11] Karunamon: haven't tried that, i'm just looking at the code examples on the rails guide, and i'm getting nils all over the place
[15:28:54] Karunamon: heh, recieved loud and clear, one sec
[15:32:18] Karunamon: workmad3: here we are - https://gist.github.com/Karunamon/f7de27b17df28cc6100e
[15:35:45] Karunamon: workmad3: that's important to know, so thank you. as far as the validator itself though, it's telling me that the data piece of the record i'm validating against is nil at this point
[15:36:33] Karunamon: workmad3: it shouldn't be nil, though. I filled in that part of the form.
[15:38:11] Karunamon: workmad3: i've got better_errors installed so I can see exactly what's happening.. request_parameters shows the form data as you'd expect, but down below, it shows "preset" as the model object with all of the parameters nil
[15:38:43] Karunamon: it's in the gist, workmad3
[15:42:55] Karunamon: workmad3: I'm starting to realize with rails that if it feels like you're doing something the hard way, you're probably not doing it right


[17:11:25] Karunamon: Hi folks - newbie question. The style guides I've read says that you don't want to put calls to your models directly in your views - okay, so I try doing them in the controller instead, but my controller vars aren't accessible inside the view (they all return nil). What's the "right" way?
[17:12:57] Karunamon: ah, one second
[17:14:07] Karunamon: ACTION facepalms
[17:14:18] Karunamon: never mind. the var was defined in the wrong function in the controller
[17:21:02] Karunamon: Mm, bit of a followup and this may be more of a general ruby question. Say I want to invoke a rails helper inside a page, but define it ahead of time so I don't have to retype the same stuff over and over?
[17:21:05] Karunamon: https://gist.github.com/Karunamon/b5d9f1ff477741578c46
[17:21:34] Karunamon: i have to get the item id from the @active_presets and then pass that in so the button gets created with the correct post data
[17:21:43] Karunamon: as written, this breaks because p.id isn't defined there
[17:22:40] Karunamon: ..at which point I could then pass in the id as an argument
[17:23:18] Karunamon: awesomeness. and the helper with that name is accessible from within the controller and view of the same name?
[17:23:46] Karunamon: webdestroya: yeah, i know, that's the error I get :)
[17:24:19] Karunamon: (i've actually got four more buttons to put on that row :s)
[17:24:54] Karunamon: kk, that makes sense
[17:25:23] Karunamon: am I constructing the button correctly? (i.e. the "show" function of the presets_controller will get the "id:" i'm passing?)
[17:26:58] Karunamon: Aha, now the magic appears. What's the right syntax for that?
[17:27:09] Karunamon: path_to 'presets#show' ?
[17:32:31] Karunamon: ah, since this is inside the presets view, i don't have to actually specify the controller
[17:33:28] Karunamon: button_to 'Details', {action: 'show', id: p.id}, class: 'btn'
[17:34:19] Karunamon: webdestroya: does that mean the button name needs to be equal to the controller path/action?
[17:35:31] Karunamon: !! I didn't even know that _path method was there
[17:35:36] Karunamon: now it makes sense, and I see what you mean
[17:37:54] Karunamon: webdestroya: is there any special reason button_to defaults to POST?
[17:38:10] Karunamon: this is just a detail action, so GET would make more sense
[17:39:52] Karunamon: webdestroya: thanks so much :D


[19:48:05] Karunamon: Hi folks; trying to do a nested block thing here. The gist of which is check if each element of an arrayof strings, returns a valid match against any item in an array of regexes.
[19:48:33] Karunamon: one liner. this is wrong, but i'm not sure why: strings.delete_if |d| d =~ regexes.each{|i| yield}
[19:48:48] Karunamon: (and I lost a brace somewhere there)
[19:55:34] Karunamon: ..man, why do I always start with the hard way?
[19:57:14] Karunamon: well wait, i want to modify the original array and trash any matching items
[19:59:03] Karunamon: ahh! union would convert the array of regexes into a single or-regex that I can use with delete_if
[19:59:05] Karunamon: bloody clever!


[16:01:41] Karunamon: Morning folks - I'm wondering if anyone is familiar with rspec enough to understand its behavior when invoked from another program
[16:02:47] Karunamon: i've got a function that does stuff, invokes rspec, and does other stuff. Problem is that rspec is run out of order. So it goes: stuff, invocation, more stuff - but the invocation happens after everything else
[16:04:06] Karunamon: Oh man, that's going to make this function a mess
[16:05:11] Karunamon: the PHP folks might be able to help you out more there
[16:05:21] Karunamon: unless your ruby is doing something really off the wall
[16:05:58] Karunamon: your function looks pretty simple, just ask the PHP guys to work through the logic.
[16:06:01] Karunamon: << - doesn't know PHP
[16:13:48] Karunamon: Hm, question. Is there a sensical way to pass a variable or some random object into rspec?
[16:14:10] Karunamon: that gets picked up by the test? I'm thinking of dumping a hash to yaml and then picking it back up in the test
[16:15:04] Karunamon: because the object is constructed by another piece of the program (I'm kind of misusing rspec here - it's validating a rather large suite of user input)
[16:16:03] Karunamon: I still have to get that object into the test
[16:17:18] Karunamon: godd2: Right, I get that, but what I mean is that's not different from the way I was thinking about doing it already. Writing another rb file and using the --include option on rspec
[16:17:29] Karunamon: that just seems really roundabout is all. I wondered if there's a better way
[16:17:57] Karunamon: Heh, fair enough.
[16:21:55] Karunamon: godd2: Also right, but I still have to pass in a known filename or something (can't just use Tempfile)
[16:27:40] Karunamon: I can't actually pastebin this (i'd love to), but the short version is that a large hash (about a good two screens full) is constructed based on user input. Rspec presents the results really nicely (and makes further tests dead simple to write), which is why I'm using that.
[16:28:01] Karunamon: and I continue or stop based on if the tests passed or not
[16:30:06] Karunamon: I /was/ doing this with another function, and just passing the hash into the function that calls rspec, problem there is that calling it doesn't block waiting for rspec to finish.
[16:30:08] Karunamon: the program just happily continues on its way
[16:33:51] Karunamon: and this function was coincidentally in the file that contains the tests. Made for a very convenient setup :P


[14:17:55] Karunamon: So here's a random question, not about solving a problem for a change: MatchData quacks like an array but lacks a .each method. Why is that?
[14:18:23] Karunamon: You can call to_a on it and get the same effect, I just wonder if there is a reason for that decision
[14:19:10] Karunamon: I mean you can do to_a if you really want to iterate through matches
[14:20:38] Karunamon: I know, I know, there are multiple ways around it, this was more just a "Huh, interesting, wonder why" type question :)
[17:13:30] Karunamon: Recursively replacing strings in arbitrary hashes containing arbitrary hashes and arrays. This works, but is ugly. Is there a better way? https://gist.github.com/Karunamon/535aca8ff69e16daf488
[17:16:37] Karunamon: oh my matz?


[14:07:15] Karunamon: silly question: what would be the most idiomatic way to represent disk partitions in Ruby code? Right now I'm using a hash, each disk is a symbol keyed to a struct containing the partition details. Looks fine in code, but is a bit hard to understand when dumped out to YAML
[14:11:24] Karunamon: This is the YAML: https://gist.github.com/Karunamon/3204c119e2abe88f060c, this is the hash it was constructed from: https://gist.github.com/Karunamon/49202b91ee27ad979bfb
[19:31:18] Karunamon: Here's a puzzle! I'm trying to do some regex, here, and the tool I'm using, http://rubular.com, is giving me different results than my pry shell and I'm not sure why.
[19:31:22] Karunamon: http://pastebin.com/EnqzKzLP
[19:33:27] Karunamon: In this case, ideally i'd get a match back that contains the "pv.02" line
[19:34:13] Karunamon: Rubular does what I mean, giving me both of them and then letting me grab the last one. Actually in a pry session, though, the last item I get is the pv.01 line
[19:34:24] Karunamon: and 2 is nowhere to be found


[22:55:03] Karunamon: and self in this case would be each individual symbol. Bloody clever!
[22:55:09] Karunamon: thanks much :)
[22:56:42] Karunamon: rubyonrailed: Resolv isn't in the namespace of your code
[22:57:56] Karunamon: Actually wait, is this an old ruby? I might be wrong here but.. yeah, isn't that a builtin as of 1.9.something)
[22:58:30] Karunamon: 2.1, works for me as soon as I do a `require 'resolv'`
[22:59:16] Karunamon: ACTION is still a little unclear on what parts of the standard lib need to be required and which are there by default