#ruby - 05 February 2018
« Back 1 day Forward 1 day »
[01:34:59] soahccc: I just finished the most ludicrous and unnecessarily complicated CLI tool ever for a simple task that could be easily replaced by a 10-line shell script but I feel good :) After living in hell for 2 weeks
[01:40:55] soahccc: also can any postgres literate tell me if you can disable foreign key constraint checks over a series of processes and time and reactivate it after a few parallel imports are complete?
[01:53:06] soahccc: I understand that. I'm a dirty mysql person you know :D and if I want to add something to our website I pull live data to my dev machine but the whole DB is huge and takes ages. So I just pull the tables I need
[01:53:30] craysiii: I'm a little confused. I monkey-patched #second onto Numeric, but when I try to test with RSpec e.g. expect(1).to respond_to :second, it fails, even though if I call 1.methods I can see it included in the list. Am I misunderstanding how respond_to works?
[01:54:06] atchoum: soahccc: what you are trying to do seems so dirty and disgusting that I don't wish to discuss it anymore.
[01:55:49] atchoum: soahccc: I wouldnot depend on production data to write a patch. I would try to create locally on my machine a copy of the database structure then selectively import few data samples.
[01:57:08] atchoum: Well methodologically speaking. It seems weird to check out production data the way you do. I wish you good luck thouhg.
[01:58:08] atchoum: alternatively you could create the table without the foreign key constraints, dump the tables you are interested in and insert the data afterward (assuming this would work with PG).
[01:58:46] soahccc: I guess it depends on the use case. Surely one could solve it "better" but our way works good, I was just asking for psql. Some employees enter the boring data in our production backend and sometimes we have to add new features for specials, etc. and we just need a few tables which might reference data that we dont need.
[02:00:02] atchoum: https://www.dbrnd.com/2017/02/postgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation/
[02:00:59] soahccc: I was just curious because I never worked with psql and I rewrote my "db sucker" tool to play with a few things and am trying to figure out if anyone is interested (also I was trying to find out if I ever can add psql support)
[02:02:05] soahccc: In the worst case I end up with a tool that only our company uses and I learned a bunch of things while creating it :)
[02:45:49] JoshB|: so I'm trying to get this to run however I'm sure I'm causing a basic mistake can you help me out? https://gist.github.com/anonymous/abe6abf9c172b0cc50928f01d59068d0
[08:25:21] geoffr: Hi all, I was wondering if there's simple way to run methods (such as FileUtils.mkdir_p ) but with sudo? For example I'm writing a service to run as an unprivileged user but that service needs to create directory for another user and I would like to avoid having to write my own system call
[08:51:18] konos5_: https://stackoverflow.com/questions/48609722/availability-of-methods-defined-in-module-singleton-class
[09:00:41] dminuoso: konos5_: It basically works like this: Take the receiver (whatever is on the left side of the dot in the method call), determine its class, and then check its ancestory for the method.
[09:01:39] dminuoso: konos5_: To allow for certain patterns to emerge, the algorithm has one little quirk - the ancestory implicitly begins with the receivers singleton class.
[09:02:26] havenwood: morfin60: Just #sub when you only want to do it once. Maybe something like: sub(/\A\/?[^\/]*/, '')
[09:02:54] dminuoso: konos5_: So "class << self" is kind of similar to self.singleton_class.instance_eval
[09:06:10] konos5_: ..yet we know that a singleton class is also an object thus its class is `Class`...
[11:11:16] dminuoso: konos5_: It's ignoring modules for various reasons, but you could think of them as beind added to the left (prepending) and right (including) of classes.
[11:12:17] dminuoso: morfin60: Well things like private/public and method_missing aside, it's fairly simple: Get ancestory, check each class in ancestory, pick first matching method.
[11:13:38] dminuoso: (The reason that I ignore private/public is this super frustrating bit, that if you mark a method as _private_, depending on _how_ you send the corresponding symbol it might either error out about calling a method, or pick method_missing instead.
[11:14:03] morfin60: as example we have something like Object->Module->Class->Foo->Instance of Foo, there can be ancestors for every level
[11:14:17] dminuoso: morfin60: And it even makes things like super easy to understand. It's just "resume lookup and call the next matching"
[11:15:00] dminuoso: It's basically "follow the super chain of the current rclass for the next matching"
[11:16:11] dminuoso: Bar is then tucked to the right side of Foo, so that the diagram would look [Foo][Bar]--super-->[Object]--super-->[BasicObject]--super-->nil
[11:16:38] dminuoso: (Note that this is only a mental model, because internally its a bit different)
[11:18:05] dminuoso: It's also the reason why I chose to do this vertically, so that "prepend" and "append" (i.e. include) works visually well.
[14:17:19] skinux: Can someone help me solve this? I've already tried reinstalling Ruby https://gist.github.com/skinuxgeek/0afebc27de9bcc0ee806d9ac0bfd5439
[14:25:46] jhass: skinux: how did you install ruby and what's your OS? Also could you amend the gist with the output of gem env?
[14:40:32] jhass: skinux: so something is referring explicitly to that? could you maybe provide some more context into what you're doing/running?
[14:41:05] morfin60: as example i have 1516208400 i want to parse it with Asia/Moskow timezone so reported date will be something like 2018-01-17 17:00:00 +03:00
[14:45:02] jhass: not really, I'm not into CMSes, sorry. The little needs into that direction I have I solve with static site generators
[14:47:38] ruby[bot]: morfin60: # => uninitialized constant DateTime (NameError) ...check link for more (https://eval.in/949902)
[14:48:00] ruby[bot]: morfin60: # => no implicit conversion of Bignum into String (TypeError) ...check link for more (https://eval.in/949903)
[14:48:13] ruby[bot]: morfin60: # => #<DateTime: 2018-01-17T17:00:00+00:00 ((2458136j,61200s,0n),+0s,2299161j)> (https://eval.in/949904)
[14:48:46] jhass: dminuoso: because they're counting from 1970-01-01 00:00:00 UTC, so in practice they're seconds since that in UTC
[14:50:09] Prutheus: mattwc: today i found a new question ... https://developer.ebay.com/Devzone/finding/CallRef/findItemsAdvanced.html look at categoryId, I can define multiple ones in a call, but how to add multiple categoryId to my params hash?
[14:50:56] jhass: morfin60: so you're saying your DB is incorrectly assuming the date you give it (in whatever way) is UTC?
[14:52:03] mattwc: prutheus: hmmm, you can't really define the same key multiple times, I think you'd be better off just making your own raw requests and constructing the URL yourself
[14:54:29] mattwc: I don't see an easy way too, hashes can only have a key defined one and the eBay API ways the same key multiple times
[14:55:14] jhass: prutheus: no idea about the particular lib you're using, but in general the first thing I would try is giving an array as the value
[14:57:21] Prutheus: hm okay yeah you are right, then i just dont support multiple categories, what else should i do :/
[14:57:46] mattwc: At this point, I'd just build the request yourself using like restclient or something
[14:58:59] jhass: morfin60: easiest might be to make sure to work with UTC dates everywhere possible and only convert to localtime at presentation
[15:54:22] zleap: hmm Who was I chatting to yesterday about the 90 day challenge, i want to ask if I can fork the repository i was given
[18:23:13] thither: I have a file with a module called DSL. In the module I have defined refinements, classes, and methods
[18:23:49] thither: I can use the refinements, but can't call the classes or functions of the method
[18:27:26] havenwood: thither: Are you using `include` as well as `using`? I do refinements in separate modules, but I haven't thought about why.
[18:29:32] thither: Thanks - I've only ever done Rails so doing actual Ruby stuff makes me look like an idiot :P
[18:29:46] havenwood: thither: I'm not sure what to recommend without seeing the code, but I suspect you might want to consider using module_function with an include, and also look at Module#included.
[18:30:36] havenwood: thither: No worries at all! If you can show some code folk here might be able to give more concrete suggestions.
[21:34:02] drocsid: Hi I'm new to ruby and defined a simple Gemfile and then try bundle install but get a bunch of errors: https://pastebin.com/aHp29ME3
[21:34:04] ruby[bot]: drocsid: we in #ruby do not like pastebin.com, I reposted your paste to gist for you: https://gist.github.com/567e1049d3f198c2bf1077382a95edbc
[21:34:04] ruby[bot]: drocsid: pastebin.com loads slowly for most, has ads which are distracting and has terrible formatting.
[21:41:23] drocsid: Zarthus: not sure about that. Thought the whole point of rvm , etc was to not install ruby stuff via my package manager...
[21:42:40] Zarthus: don't know anything about rvm, but when building native extensions it seems to require ruby headers
[21:48:04] drocsid: Zarthus: I will give it a shot. Thanks. Ruby packaging and stuff looks simple but is confusing...
[21:49:03] Hanmac: for most things it makes sense that you don't need the dev parts if you want to use a lib or application
[21:49:09] drocsid: Hmm yeah I dunno got that rvm business to install ruby as suggested. But I dunno.
[21:52:23] Hanmac: hm no the problem is bundler currently seems to use system ruby, not the one you installed with rvm
[21:55:08] drocsid: Not sure what happened but I think installing `ruby-dev` allowed the bundler to install it now...
[21:55:25] havenwood: drocsid: You either don't have bundler installed on your RVM Ruby (as suspected), or system Ruby bundler is ahead in the path.
[21:57:16] drocsid: Allright well using system ruby now. Not sure how to swap. But it was able to install the module
[22:04:47] drocsid: anyhow I was able to install the gems using bundle after installing `ruby-dev`. Not terribly happy about it, but seems that I have issues regarding the rvm installed ruby. I followed the instructions regarding ruby installation at the rvm site...
[22:05:28] drocsid: So I am able to move forward. Think installing the `ruby-dev` package helped. Maybe all this is 2nd class in debian.. I don't know.
[22:05:42] havenwood: drocsid: I'm suspicious you somehow ended up doing a multi-user RVM installation (added sudo?) instead of the recommended single-user install.
[22:07:09] havenwood: drocsid: I'd suggest doing an `rvm implode --force` and then completely restarting your terminal to clear lingering env vars.
[22:13:08] havenwood: drocsid: As a non-root user, without sudo: \curl -sSL https://get.rvm.io | bash
[22:13:12] drocsid: the basic install instructions. Want to move on to writing code but yeah I can try that again later.
[22:15:36] drocsid: `Upgrading the RVM installation in REDACTED Upgrade of RVM in REDACTED is complete.`
[22:48:18] drocsid: I'm trying to understand rubies' match as it is used here: https://github.com/socketry/rubydns/blob/master/examples/flakey-dns.rb
[22:49:40] drocsid: I created a regex pattern on http://rubular.com/ with a single match group: single_ip_match_group = '/ip-([^.]*).*internal/'
[22:50:22] havenwood: drocsid: https://github.com/socketry/rubydns/blob/8f90f12b63911dade1ac003b7c3fca531dd2e335/lib/rubydns/rule_based_server.rb#L34-L44?ts=2
[22:50:59] ruby[bot]: drocsid: Pry, the better IRB, provides easy object inspection `ls`, `history`, viewing docs `?`, viewing source `$`, syntax highlighting and other features (see `help` for more). Put `binding.pry` in your source code for easy debugging. Install Pry (https://pryrepl.org/): gem install pry pry-doc
[22:51:54] havenwood: drocsid: Sure, you can use the docs online. Or generate them yourself for local web browser use.
[22:59:06] elomatreb: drocsid: For future reference, there are some sites that generate and host the embedded documentation in gems, e.g. for your gem/method: http://www.rubydoc.info/gems/rubydns/2.0.1/RubyDNS/RuleBasedServer#match-instance_method
[23:00:00] drocsid: Still not sure why my match isn't working. The pattern seems to be ok via rubular...
[23:03:48] drocsid: Anybody with a good guess. My string could be something like ip-88.22.355.23-us-east-1.computer.internal and my pattern is '/ip-([^.]*).*internal/'
[23:09:17] drocsid: Yeah I want to match and then extract the IP. The match group contains the ip delimited by - . Then I do gsub. My issue is the pattern seems to match in rubular but not via a modified ruby dns example likehttps://github.com/socketry/rubydns/blob/master/examples/flakey-dns.rb
[23:09:26] havenwood: drocsid: Do you mean "any character except a newline" by that ^, because the dot isn't escaped so that's what it means.
[23:12:44] elomatreb: drocsid: So, what do you know about the string? Is the part after the IP (-us-east-1.computer.internal) constant?
[23:39:00] drocsid: elomatreb: I mistyped the match string. ip-88-22-355-23.us-east-1.computer.internal is what I'm trying to match and again my pattern is the same ip-([^.]*).*internal