#ruby - 06 February 2018
« Back 1 day Forward 1 day »
[00:09:32] nchambers: when writing a commandline app in ruby, is it common to write a unit test for the entry point file in addition to the actual source files?
[00:14:16] drocsid: nchambers: not sure about ruby but it sounds like a good idea to me... Not quite sure what you mean by entry point file but assume it's like the launcher class... but I'm a ruby novice.
[00:16:08] nchambers: drocsid: this is my entry point file: https://gitlab.com/ntchambers/cherrybomb/blob/master/bin/cherrybomb its what gem build makes as the entry point
[00:20:49] drocsid: nchambers: I would test that class if I was a test driven developer or if using it in production. Good to test all the things...
[00:21:45] elomatreb: nchambers: It's of course never a bad idea to test something, but entry files are often left untested because it would incur significant overhead, since they have to have side effects by design
[00:23:42] drocsid: One thing I understand about TDD is the beleif that tests should be written first, then code written and not the other way around...
[00:24:35] drocsid: To be honest I don't always write TDD when writing scripts, etc. But when I do I feel more confident about what I'm doing...
[03:11:11] nchambers: can someone explain the bevahior I'm seeing here? http://ix.io/Fl2 why does the first one return nil, but the second one returns 0?
[03:11:50] havenwood: nchambers: The first one didn't match and the second one matched at position 0.
[03:13:33] nchambers: so if I wanted to test if a given string matched a regex, I would just want (/regex/ =~ str).nil?
[03:14:49] havenwood: nchambers: That way there are no captures, so it's faster and takes less memory.
[03:21:27] craysiii: How does rspec #respond_to determine which methods there are? I've skimmed the source but haven't found anything telling yet. I ask because I have monkey-patched a method onto Numeric and it's not passing a respond_to expectation. https://gist.github.com/craysiii/9b6adaf1ff713af9fd0eabff6fc11c55
[07:59:30] matejz: I have this definition in my Gemfile: gem 'puppet', ENV['PUPPET_GEM_VERSION'] || '~> 3.8'
[10:14:01] konos5_: Hi, in irb `respond_to?(:define_method, true)` returns true. However since `:define_method` is defined in `Module`, `:define_method` should only be available within a class definition and not in main. Why?
[10:19:08] ruby[bot]: dminuoso: # => [:new, :allocate, :superclass, :<=>, :module_exec, :class_exec, :<=, :>=, :==, :===, :include?, :inc ...check link for more (https://eval.in/950542)
[10:23:05] ruby[bot]: dminuoso: # => [:include, :using, :public, :private, :define_method, :DelegateClass, :sprintf, :format, :Integer, : ...check link for more (https://eval.in/950548)
[10:27:34] dminuoso: konos5_: The "default receiver" is always "self". In top level scope (outside any class/function) that self is a special object called "top self" (which is usually presented as "main")
[10:28:30] dminuoso: konos5_: If you do not specify a receiver, it defaults to `self` whatever that is in your context. So if you write "define_method", it's kind of equivalent to: self.send(:define_method)
[10:29:02] dminuoso: And that "top self" object - like any object - has a singleton class. That singleton class receives some methods when the ruby VM boots up.
[10:32:29] dminuoso: konos5_: Assume the red one was top self, and you just erased the RClass String.
[10:33:09] dminuoso: konos5_: The reason you happen to have define_method has to do with how ruby bootstraps.
[10:34:10] konos5_: Either way main.singleton_class shouldn't be getting define_method since its stored in `Module`
[10:34:41] dminuoso: konos5_: Core functions exist as C functions. Ruby them creates a "link" in modules to those C functions
[10:37:29] dminuoso: konos5_: If you look closely it actually uses two different methods. So strictly speaking its not the same.
[13:35:16] Bish: how do i make sure, that another customer doesn't add the subdomain, too, and can use it
[13:36:19] Bish: a.e. user wants to use tracking.somedomain.com to point to my server.. adds in in my software, and my software tests if that A/CNAME entry is made, before he can use it
[13:36:41] Bish: then another customer comes and adds tracking.somedomain.com .. points it to my server, and will get it, too
[13:44:01] canton7: Bish, is this more a question of making sure that people don't register a subdomain which doesn't belong to them?
[13:44:36] dminuoso: Bish: You either need to maintain a single registry to avoid collisions, or you need a distributed way of committing a slow transaction with proper rollback semantics (which sagas give you)
[13:44:47] canton7: most people do that by requiring that the person creates a TXT record with a magic value you supply
[13:46:57] canton7: Bish, so user signs up, provides their subdomain. You say "OK that's great, I need you to create a txt record with <this value>. User does that, clicks "check now". You check for the presence of that TXT record with that value. If it's found, all good, the user controls that subdomain
[13:47:01] Bish: dminuoso: the customers. i have a tracking server, which customers need to add on their page
[13:47:25] Bish: and if people want "bishcompany" in their code.. their can add their own cname/a entry
[13:48:56] dminuoso: Bish: Ahh that explains it. I thought you were somehow doing some poor mans DNS reselling.
[13:49:29] dminuoso: Bish: You cant test for identity anyway. But you can check for authorization by handing them a token that they need to present to you.
[13:56:44] burgestrand: well, doesn't matter I guess, something something crypto something something, then use libsodium: https://github.com/crypto-rb/rbnacl
[14:03:22] burgestrand: Bish for most people the primitives in openssl are too easy to use in an incorrect way
[14:05:52] burgestrand: Bish I'm pretty much paraphrasing the readme, but sodiums API is designed to make it easier to use in a secure way and harder to misuse in an insecure way
[16:59:46] lesce: I get "Bundler::PermissionError: There was an error while trying to write to `/bundle`. It is likely that you need to grant write permissions for that path.
[17:36:37] cthulchu_: I'm new to ruby. Am I understanding it correctly that Ruby is higher than even Python?
[17:42:35] cthulchu_: mhm, as any high-level language. Would you say Ruby's similar to Php and JS as well?
[17:44:19] SeepingN: it's a good replacement for PHP. But there's no client side Ruby scripting for browsers that I'm aware of
[17:45:43] eam: python and php are reference counted, arguably you could say that a gc is a higher level abstraction -- but I don't think this super significant
[17:46:16] eam: and this can vary between implementations -- it's more of a detail of a particular implementation than of the language itself
[17:46:24] cthulchu_: I replace php with Node. But Ruby is used in our QA scripting to work with Selenium and I wanna play with it, so Ruby.
[17:55:14] SeepingN: I am in love with Ruby for *nix scripting. Use it extensively to manage millions of devices
[17:56:53] eam: ooh, which solar company is using ruby to run their inverters? I got solar last year and am interested in this :D
[17:56:54] havenwood: SeepingN: Opal gives you Ruby in the browser: https://github.com/opal/opal#readme
[17:58:03] soahccc: I'm looking for a new side project (CLI, something with ncurses) but can't think of anything useful :(
[17:59:48] soahccc: I had so much fun with parallelization, deadlocks and racing conditions... my sudoku
[18:55:03] eam: I'm working through figuring this out on my end, but would anyone happen to know why Net::HTTP would have a problem automatically decoding gzip content? Deflate works fine
[19:24:08] baweaver: eam: more than likely it's stupid in what it does automatically. I seem to remember it disliking redirects as well unless told explicitly otherwise.
[19:25:29] eam: the weird thing is that adjusting the accept-encoding from gzip, deflate to just deflate works ok
[19:34:57] eckhardt: eam i don't think we tested the behavior by just...not setting the accept-encoding header?
[20:00:15] arcturiaen: faraday => https://github.com/lostisland/faraday_middleware/wiki/Gzip-Compression
[20:02:44] drona6: I'm trying to get a build to pass on CircleCI. It's failing with "Could not open library 'libsodium.so': libsodium.so: cannot open shared object file: No such file or directory (LoadError)". I can solve this locally with `sudo apt-get install libsodium-dev`, but I don't know enough about CircleCI to tell the CI machine to also install that lib. Does anyone know how/where to configure CircleCI with custom packages to install on the
[20:31:33] jcalla: had to learn Ruby for work over the weekend. you guys have an interesting language!
[20:32:13] jcalla: just one main question, do you have a great alternative to irb (similar to ipython)?
[20:33:30] ruby[bot]: jcalla: 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
[20:34:15] jcalla: thanks. i tried that out briefly last night. however, the syntax highlighting didn't kick in until i submitted a line
[20:35:33] ruby[bot]: havenwood: # => can't convert nil into Integer (TypeError) ...check link for more (https://eval.in/950997)
[20:37:25] havenwood: >> class NilClass; undef to_i end; nil.to_i # Don't actually undefine #to_i though...
[20:37:26] ruby[bot]: havenwood: # => undefined method `to_i' for nil:NilClass ...check link for more (https://eval.in/950999)
[20:43:45] Prutheus: Hello. A Rails question: The application template has something like that `<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>` in it ... I also want to include all tempaltes and themes in the mailers template, but this line of code jsut embeds them relative, not absolute, so their path is /assets/.... and not https://www.domain.com/.....
[20:51:08] Prutheus: in the mail, from the usage of the code i showed you, there are some links generated like: `<link rel=3D"stylesheet" media=3D"all" href=3D"/assets/application.se= lf-596c2fa6c5d7dbf2dd37bac9a44f82d983db1a31b09c0518e0108a49324d666f.css?b= ody=3D1" data-turbolinks-track=3D"reload" />`
[20:51:33] Prutheus: but this link can not get resolved from my email client cause there is no web domain/ip given in front of the path
[21:04:40] dc30: basically I'm catching the output of command as a hash and need to check if specific key value is 0 or NULL
[21:18:32] dc30: if it would be easier https://github.com/sensu-plugins/sensu-plugins-mysql/blob/master/bin/check-mysql-replication-status.rb
[21:20:00] dc30: if the results is an array of hashes each_hash will only work on the first element in array
[21:45:08] Dude: Why are there huge left & right margins on Rails pages for all the content within <% yield %>? My headers take up the width of the entire browser. I googled this and cannot find any discussion about it, which makes me think I didn't use the correct search terms.
[21:52:31] drona6: dude: I think you're describing an issue outside the context of Rails itself. The margins you describe would be the result of CSS, which you can certainly modify. Check app/assets/stylesheets for any CSS files. Don't hesitate to follow up here if I've misunderstood the question. Also #RubyOnRails might be a better place for the question, if it does end up being very Rails-specific.
[21:55:35] Dude: drona6: Thanks. I tried joining #Rails which doesn't exist. I already checked stylesheets but body etc doesn't have margins set. I was able to get a sidebar all the way to the left but still have ridiculous padding between sidebar and content. This might be a bootstrap thing since I'm using that gem.
[21:56:24] drona6: dude: Sounds good. If possible, paste a link to the repo. It shouldn't be too hard for someone to check out your Bootstrap usage and identify the issue.
[21:56:52] drona6: You could also look for a channel for HTML or CSS specifically, since it sounds like this issue is front-end related. Good luck!
[22:30:05] Dbugger: I just saw this line: "@user ||= ... if something" and I am not sure what is the order of operators