Activity Graph

Page 1 of 1


[21:20:08] jolamb: has joined #ruby
[21:32:51] jolamb: has left #ruby: ("WeeChat 1.9.1")


[22:36:37] jolamb: has left #ruby: ("WeeChat 1.9.1")


[19:37:29] jolamb: I want to initialize a value "new_array" by composing an array from a possibly defined array and a possibly defined scalar, but lazily. This is what I've come up with, but is there a Better Way? `(new_array ||= []).push(*(possibly_existing_array || [])).push(*([possibly_existing_scalar] || []))`
[19:37:39] jolamb: Using .push to enforce a particular order
[20:20:20] jolamb: havenwood: yeah, that's probably what I need to do
[20:20:26] jolamb: (sorry for delay, had a meeting)


[08:18:26] jolamb: Ping timeout: 252 seconds
[08:20:12] jolamb: has joined #ruby


[23:11:56] jolamb: Quit: ZNC -
[23:30:32] jolamb: has joined #ruby


[05:13:09] jolamb: Ping timeout: 255 seconds


[18:58:21] jolamb: So this is basically the same code repeated 5 times; is there a good ruby idiom to make this less repetitive?
[19:00:51] jolamb: I was thinking something like `['labels', 'members', 'cards', ...].each do |json_type|` ... `send("load_#{json_type}", object_json, trello)`
[19:01:15] jolamb: but that smells to me
[19:24:52] jolamb: jhass: sorry, someone stopped by my desk. Reading now
[19:30:10] jolamb: jhass: yeah, the load_xyz methods all cache the loaded objects, so I could just load them all and then move the code to populate the trello object into the TrelloHelper class, and use accessors


[05:06:26] jolamb: *.net *.split
[05:14:00] jolamb: has joined #ruby


[14:48:36] jolamb: *.net *.split
[14:55:09] jolamb: has joined #ruby


[02:29:00] jolamb: has joined #ruby


[15:55:02] jolamb: I have a sacreligious question: Is there a setting or an add-on cop for Rubocop to flag "unless" and convert it to "if !"?
[16:41:25] jolamb: isene: look at pp
[16:42:05] jolamb: isene:
[16:42:09] jolamb: one way to do it
[16:42:20] jolamb: isene: why not serialize to json or yaml tho?
[18:22:23] jolamb: BlaDe^: presumably your call is returning nil, this the NoMethodError in the first trace
[18:23:03] jolamb: BlaDe^: The second stack trace is probably because @reader.inspect has a bug - what does "byte!" do here?
[18:23:41] jolamb: BlaDe^: oh wait, I'm misreading that bit
[18:24:13] jolamb: b = byte! calling the method in line 20
[18:24:59] jolamb: BlaDe^: [139] pry(main)> nil & 0x7F => false
[18:26:12] jolamb: BlaDe^: b is nil because is returning nil, you're catching the exception but you're not returning a valid value from inside the rescue block, so the method is returning nil
[18:27:34] jolamb: BlaDe^: what is @reader?
[18:29:25] jolamb: BlaDe^: let me rephrase - what are you passing in as your reader when you initialize BinaryDecoder|
[18:35:11] jolamb: BlaDe^: I'm guessing whatever reader it's using isn't blocking, so read(1) when there's no data ready is returning nil
[18:35:53] jolamb: so maybe it needs to be: if (b = b.unpack('C').first


[18:44:09] jolamb: ok, circular dependency problem. I have files lib/a.rb and lib/b.rb. b.rb depends on a.rb - `requires 'a'`. I have test/test_a.rb and test/test_b.rb. test_a.rb has `require a`, test_b.rb has `require b`. When I run "rake test" it warns about circular dependencies, because - I think - a.rb gets required twice
[18:44:19] jolamb: test_a.rb -> a.rb; test_b.rb ->
[18:44:28] jolamb: test_a.rb -> a.rb; test_b.rb -> b.rb -> a.rb
[18:45:17] jolamb: Is this happening because I'm doing something wrong when I require a from b, or is this warning something I should suppress/ignore?
[18:46:59] jolamb: kinduff: I don't get what you mean by "require at higher level (b.rb -> a.rb)" - b.rb already requires a.rb
[18:54:01] jolamb: kinduff: I'm pretty sure that's what I've got more or less. Lemme poke at this a bit more
[18:58:30] jolamb: kinduff: hrm, looks like it's actually a circular dependency in the oauth gemn
[19:02:28] jolamb: kinduff: looks that way. Any way I can tell ruby to skip warnings on external deps?
[19:06:14] jolamb: I've got a dependency on ruby-trello. It depends on oauth. oauth.rb requires oauth/client/helper, which requires oauth/consumer, which requires oauth/client/net_http, which requires oauth/client/helper
[19:06:38] jolamb: kinduff: ^^ there's the context


[17:56:47] jolamb: Is this pattern for object initialization as bad and awful as I think it is?
[17:59:57] jolamb: matthewd: hah, excellent point
[18:00:58] jolamb: Papierkorb: matthewd: ok I know there are problems there, bear in mind this is inherited code
[18:01:16] jolamb: that is fairly old, and most frequently updated under emergency conditions :D
[18:01:54] jolamb: elomatreb: what Papierkorb said.
[18:02:07] jolamb: ACTION bangs head against desk for emphasis
[18:08:11] jolamb: elomatreb: hah, take a look at this mess:
[18:08:31] jolamb: the code HAS to be stable, because it's so hostile to modification
[18:10:56] jolamb: I really have to pick my battles when I work on this stuff, thus why I only asked about that one particular pattern just now
[18:16:11] jolamb: Papierkorb: yeah, that's the goal. I've started trying to add unit tests, so at least I can verify changes
[18:16:16] jolamb: but there's a lot to test there...


[01:01:12] jolamb: Ping timeout: 260 seconds
[01:06:31] jolamb: has joined #ruby
[02:12:43] jolamb: Read error: Connection reset by peer
[02:20:31] jolamb: has joined #ruby


[19:56:48] jolamb: Are there any tools to make refactoring ERuby templates easier? Preferably that integrate nicely with emacs?
[19:57:48] jolamb: I'd like to extract complex logic into a helper lib, e.g.
[19:58:32] jolamb: adaedra: it's not the HTML that's the problem :D
[20:00:31] jolamb: adaedra: what's a good alternative?
[20:00:58] jolamb: adaedra: note that I inherited this code, I wouldn't have made anything like this willingly :P
[20:01:36] jolamb: Papierkorb: adaedra: it's not really the er
[20:01:41] jolamb: erb that's a problem though
[20:01:55] jolamb: it's the huge blocks of logic that should be refactored out
[20:02:31] jolamb: sorry about the stutter, "b" is right next to "enter" on this typematrix kb and my muscle memory has never quite adjusted
[20:03:33] jolamb: I guess I just need to do this the old-fashioned way, by moving logic out chunk-by-chunk to see what breaks :/
[20:04:45] jolamb: arrrgh wtf
[20:04:51] jolamb: adaedra: That's just mean
[20:05:09] jolamb: you've obviously spotted the missing tests :(
[20:07:18] jolamb: adaedra: yeah
[20:07:31] jolamb: it is Reliable Code that has Gotten Us This Far
[20:07:49] jolamb: it's very modification-hostile
[20:09:22] jolamb: adaedra: that's the dadgum truth
[20:12:04] jolamb: adaedra: roger that
[20:16:41] jolamb: adaedra: Papierkorb: any recommendations on unit-testing libraries for non-rails code?
[20:20:19] jolamb: havenwood: why minitest over rspec3?
[20:21:20] jolamb: havenwood: that all sounds pretty good
[20:21:28] jolamb: downsides?


[04:46:44] jolamb: Ping timeout: 258 seconds
[04:48:11] jolamb: has joined #ruby


[13:16:46] jolamb: Remote host closed the connection
[13:40:32] jolamb: has joined #ruby


[05:49:41] jolamb: Quit: ZNC -
[06:20:32] jolamb: has joined #ruby


[17:06:32] jolamb: Quit: ZNC -
[17:20:32] jolamb: has joined #ruby


[18:39:05] jolamb: Quit: ZNC -
[18:50:32] jolamb: has joined #ruby


[18:41:13] jolamb: has joined #ruby
[18:44:36] jolamb: I have a bunch of label strings I need to parse that are in the form "phase-(optional)product-(optional string)1.(optional string)2.(optional string)3.(optional string)4", e.g. "targeted-5.4.1" or "completed-someproduct-x2.y5.r1" or "proposed-otherproduct-"
[18:45:45] jolamb: Currently these are being parsed into [phase, product, major, minor, patch, fixup] using a very complex regex and then slurping up the relevant data from $1 $2 $3 etc.
[18:46:31] jolamb: beyond using .match, is there a more correct way to parse out these kinds of almost-semantic-versioned strings?
[18:48:53] jolamb: matthewd: yeah, it's nasty, but I really think this is Just Plain Wrong: /^(\w+)-((\w*)-)*((?:\D*)?(\d+)(?:.(?:(?:\D*)?(\d+)))?(?:.(?:(?:\D*)?(\d+)))?(?:.(?:(?:\D*)?(\d+)))?)/
[18:49:27] jolamb: matthewd: I'm not worried about making it an object so much as extracting the content in a more sane manner
[18:50:26] jolamb: matthewd: yeah, there's some other stuff built into it, e.g. the version part always needs to match at least major.minor
[18:53:10] jolamb: matthewd: huh, I'd never seen .scan before
[19:02:20] jolamb: matthewd: I'm actually throwing away the strings in front of the version numbers, so I think just .scan(/\d+/) will do what I want
[19:11:51] jolamb: apeiros: I thought about that...
[19:13:16] jolamb: apeiros: gotcha.
[19:13:20] jolamb: I think I'm set now


[08:09:06] jolamb: Quit: ZNC -
[14:01:03] jolamb: has joined #ruby


[02:20:32] jolamb: Ping timeout: 260 seconds
[02:21:45] jolamb: has joined #ruby


[07:32:16] jolamb: Quit: ZNC -
[08:20:33] jolamb: has joined #ruby


[19:39:38] jolamb: Any faraday wizards here?
[19:40:01] jolamb: I'm trying to figure out how to e.g. skip a specific middleware in the stack for just one request


[00:17:14] jolamb: *.net *.split
[00:23:11] jolamb: has joined #ruby


[20:19:01] jolamb: Any Faraday users in here?
[20:19:24] jolamb: I'm trying to switch some code over to it to take advantage of faraday-http-cache
[20:20:01] jolamb: I'd like to know if it's possible to get Faraday to impersonate Net:HTTP for my code, or do I need to adapt my code to do things the Faraday Way
[20:24:50] jolamb: jhass: :/ ok
[20:33:26] jolamb: jhass: nope, just trying to be a better github citizen
[20:48:28] jolamb: zenspider: cache API responses, take advantage of conditional responses to cut down on my rate limit abuse
[20:49:27] jolamb: zenspider: the code I'm adapting has some idiosyncracies, and a lot of it depends on Net:HTTP
[20:51:16] jolamb: zenspider: the app is already written. Lots of processes depend on it, and there's no unit tests
[20:51:30] jolamb: and I didn't write it so don't hit me. :D
[20:53:22] jolamb: zenspider: we're working on replacing it Any Day Now, but until that happens I'd like to make it a bit better-behaved


[00:46:47] jolamb: Ping timeout: 260 seconds
[00:49:51] jolamb: has joined #ruby


[17:23:15] jolamb: Read error: Connection reset by peer
[17:28:09] jolamb: has joined #ruby
[17:28:11] jolamb: Read error: Connection reset by peer
[17:34:08] jolamb: has joined #ruby


[09:01:06] jolamb: *.net *.split


[01:04:37] jolamb: Ping timeout: 260 seconds
[01:12:14] jolamb: has joined #ruby


[08:22:23] jolamb: Quit: ZNC -
[10:50:31] jolamb: has joined #ruby


[19:31:16] jolamb: so I have some instance methods that are tightly coupled to one another but which aren't used by the other methods in a class. I could extract them into a module and then include that module in my class, but that seems like bad programming
[19:31:46] jolamb: That is, it seems bad because these methods *do* call other instance methods in the class.
[19:33:52] jolamb: It seems like bad locality of reference if the module calls a bunch of methods that are defined in some other class, maybe even in some other file. Is there a better way to encapsulate these, or at least a way to make it clear where these mystery instance methods might be coming from?
[19:45:16] jolamb: hxegon:
[19:45:27] jolamb: hxegon: this is inherited code btw
[19:47:32] jolamb: al2o3-cr: yeah I know. That's not the problem I'm trying to solve right now. :)
[19:48:42] jolamb: al2o3-cr: well I do now, heh
[19:50:28] jolamb: hxegon: happy new year
[19:51:41] jolamb: hxegon: comes from Trello::Card :)
[19:52:17] jolamb: I am the customer, so I can make API changes
[19:54:28] jolamb: hxegon: I know
[19:55:37] jolamb: hxegon: you mean monkeypatching it? I'd rather not
[19:56:07] jolamb: If I were to go down that rode, I'd extend Trello::Card instead
[19:56:11] jolamb: s/rode/road/
[19:56:53] jolamb: hxegon: googling "ruby refine"
[19:58:27] jolamb: hxegon: I see. That's pretty cool
[19:59:48] jolamb: I'd still rather subclass it so that it's evident to the next poor soul that we're not using the "pure" ruby-trello API
[20:00:24] jolamb: hxegon: gotcha
[20:05:38] jolamb: hxegon: yup
[20:06:05] jolamb: hxegon: I never knew the term "cyclomatic complexity" until I started working on this code. :)
[20:07:56] jolamb: hxegon: I've got a decent amount, but I wouldn't characterize all the experience as "good"
[20:08:05] jolamb: at least not in terms of the eventual output :)
[20:13:42] jolamb: hxegon: will do, thanks


[19:46:52] jolamb: has joined #ruby
[19:50:26] jolamb: with ruby-mri, can I specify a line of code to execute before the programfile? e.g. I have a script that's not using bundler, and which has a weird json requirement, so I'd like to run `gem 'json'
[19:50:46] jolamb: `gem 'json', '< 2.0'` that is
[20:00:53] jolamb: jhass: huh, good point


[07:35:06] jolamb: Ping timeout: 244 seconds
[07:37:32] jolamb: has joined #ruby


[08:12:02] jolamb: Ping timeout: 244 seconds
[08:13:47] jolamb: has joined #ruby


[06:57:30] jolamb: Ping timeout: 258 seconds
[06:59:06] jolamb: has joined #ruby


[08:04:52] jolamb: Quit: ZNC -
[08:40:32] jolamb: has joined #ruby
[08:48:08] jolamb: Quit: ZNC -
[09:00:32] jolamb: has joined #ruby


[07:06:42] jolamb: Quit: ZNC -
[07:30:32] jolamb: has joined #ruby
[19:41:46] jolamb: Ping timeout: 252 seconds
[19:47:46] jolamb: has joined #ruby


[20:27:36] jolamb: *.net *.split
[20:27:46] jolamb: has joined #ruby


[10:53:35] jolamb: Ping timeout: 260 seconds


[17:35:18] jolamb: is `v == :a || v == :b` better or worse ruby than `[:a, :b].include? v` ?
[17:37:20] jolamb: faster when looping over 100-300 elements
[17:39:09] jolamb: GarethAdams: just some variable containing a symbol, which may be :a or :b
[17:42:05] jolamb: GarethAdams: nope
[17:42:19] jolamb: ok, just timed it, the first form is faster
[17:44:21] jolamb: GarethAdams: I understand and agree. This wasn't a question of selection though, I was just taking an action depending on some property of the current item in the set being iterated over
[17:46:37] jolamb: thanks all


[02:15:04] jolamb: Ping timeout: 240 seconds
[02:21:52] jolamb: has joined #ruby
[02:36:39] jolamb: Ping timeout: 246 seconds
[02:37:54] jolamb: has joined #ruby


[08:55:57] jolamb: Quit: ZNC -
[11:40:32] jolamb: has joined #ruby


[23:45:08] jolamb: Ping timeout: 260 seconds
[23:46:03] jolamb: has joined #ruby


[05:37:40] jolamb: Ping timeout: 264 seconds
[05:39:44] jolamb: has joined #ruby


[08:12:11] jolamb: *.net *.split


[18:07:15] jolamb: has joined #ruby
[18:24:28] jolamb: are there any libs which provide useful common magic numbers in the standard library?
[18:25:31] jolamb: pipework: :P
[18:28:24] jolamb: havenwood: nope. nevermind, I think I was just being silly