#ruby - 13 February 2019
« Back 1 day Forward 1 day »
[02:49:51] elcontrastador: Any ruby UDP sockets programmers online that want to pair program a fun project for Polycom phone paging via multicast? Polycom has document the signaling and audio format here: https://support.polycom.com/content/dam/polycom-support/products/voice/polycom-uc/other-documents/en/2017/audio-packet-format.pdf
[15:06:56] mensvaga: I'm running ubuntu 18.04 . There's a system package, bundler 1.16.1-1 , which is installed.
[15:09:05] mensvaga: But when I try and run my script, I get: Bundler could not find compatible versions for gem "bundler": , In Gemfile: bundler (~> 2.0) , Current Bundler version: bundler (1.16.1)
[15:16:50] Eindoofus: anyone else find enumerators annoying when first learning Ruby? i'm reading up on the unending number of enumerator options and functionality, and i'm hating it. not sure whether i should be enjoying this or if i should just power through it
[15:18:03] mensvaga: And, it depends. Would you like enjoying learning a spoken language by reading a dictionary, and getting pissed off because of the "number of words" ?
[15:18:47] mensvaga: When I first started learning this stuff, it was hard to discern the two; mainly because it was difficult to anticipate what was going to be important later
[15:18:47] Eindoofus: it's more like the overwhelming variations in the usage of grammar for the same sentence
[15:19:23] mensvaga: The book is just presenting the information to you in what the Author thought was a useful way.
[15:20:42] mensvaga: It seems like what you need to do is get confident in your ability to "just look stuff up" when you need to, and then skip the "boring" parts.
[15:23:13] mensvaga: eindoofus: Another thing: You probably already made the leap and didn't realize it.
[15:23:42] mensvaga: Were you sitting there thinking, "Yeah, ANOTHER Iterator. I get it. Ruby has iterators. Oh, what's this? ANOTHER iterator? How many pages...? UGH"
[15:24:15] mensvaga: Yeah, at that point, you know what an iterator is. You know what a data type is, you can lookup up iterators for data types.
[15:24:42] mensvaga: This is when "actual" speed reading applies. Look at the headings, look at the first sentence, and then just breeze through those pages.
[15:25:51] Eindoofus: it's interesting you mention that. now that i think about it i use such books as a crutch since i lack the confidence to do anything without them. i also don't trust in my ability to skim information and remember that the concept exists.
[15:27:29] mensvaga: If you've driven a car, they're pretty much "all the same", except where the shifter is, and how to turn on the headlights, etc.
[15:27:59] mensvaga: You know tire pressure is a concept. You don't need to read and learn the correct tire pressure measurements before you use somebody else's car.
[15:29:34] mensvaga: If a light comes on, pull over, look up what the warning indicators are in the manual. You probably didn't learn what every damn light in the car does. But, you know how to look it up :)
[15:33:00] phaul: sounds like I'm trolling but I'm geniunely curious how that book defines iterators
[15:36:29] mensvaga: If you're familiar with Tensors, some people define Tensors as "Things that Tensor operations can be done on."
[15:36:48] mensvaga: Which, when you're first learning about them does NOT help you understand what they are.
[15:37:01] mensvaga: But when you know what they are, you're answer is going to be "Things you can do Tensor things with."
[15:37:29] mensvaga: Which makes it hard to figure out if people actually know what they're talking about.
[15:38:58] phaul: also makes it hard when books come up with concepts on their own, that are not part of a language. Makes ppl familiar with the language confused
[15:39:41] mensvaga: My favorite example of that is indentation style in books. Why do people use the indentation style that's in books? Books need to save whitespace.
[15:52:35] phaul: ah, Kernel#iterator? is an alias to block_given?. I never knew. Altough "mildly depricated".
[15:58:41] TheBrayn: https://gist.github.com/mmerfort/86d2a1fd33828d8fad7ccb4a0a504140 how do you think this could be improved?
[16:00:34] phaul: deep_key_to_string vs deep_string_transform_key, arent those supposed to be the same?
[16:06:04] phaul: I'm not sure if it's an improvement but you can tranfer the conditional into the array, [ k.to_s, v.instance_of? Hash ? v... : v ]
[16:16:09] rubydoc: # => wrong element type Integer at 0 (expected array) (TypeError) (https://carc.in/#/r/68lg)
[16:42:09] mensvaga: I thought "bundle install" was when you wanted to fetch the requirements for your gem locally.
[16:45:19] blerrp: If this is your first time running the bundle gem command, you will be asked whether you want to include a the CODE_OF_CONDUCT.md and LICENSE.txt files with your project.
[16:50:31] mensvaga: And now, I need to write documentation so people can take the adventure with me.
[16:55:17] mensvaga: And it's going to be added to a local gem repo, but that will just be a tiny shell script.
[16:58:57] mensvaga: That is a possibility. However, designing and maintaining a secure infrastructure in that way was out of the scope for the current project.
[16:59:30] mensvaga: Basically, our users can already authenticate to where they need to, and have the appropriate access. So, a tiny shell script which writes things to a directory that's exported by apache was all we needed.
[17:00:02] mensvaga: Yes, if we need to manage lots of these in a different way, we'll do that. We already host our own packages with other packaging systems, and have workflows for them.
[17:01:14] mensvaga: Specifically, I'm concerned with if running "gem install bundler" as root is a "good" thing. I want it to be available to all users
[17:01:40] mensvaga: I don't want the users to have to install much. But, if the user uses "gem install" in their environment, I want it to work.
[17:03:05] mensvaga: I want for a user to be able to run bundler without having to install anything. But I want their own environment to overried what's installed system-wide
[17:03:34] mensvaga: So, if running as root doesn't prevent them from installing their OWN version of bundler, than I'm OK with installing it system-wide
[17:23:13] havenwood: mensvaga: You can have multiple locations in GEM_PATH, one of which can be GEM_HOME.
[17:23:37] havenwood: mensvaga: RubyGems will install to GEM_HOME, but look for gems in all the locations in GEM_PATH.
[17:24:36] mensvaga: For the case issue, is there a document with ALL of such standards so I can make sure I adhere to them?
[17:26:58] ngw: I'm unsure on how to cleanly have a huge chunk of data in a class. This data is basically static (Elasticsearch index definition) and is basically a normal Hash
[17:26:58] havenwood: mensvaga: You have an issue with you executable location. I the spec you say "exe" but you put it in the "bin" dir.
[17:28:00] ngw: I'm fiddling with the idea of having an external configuration file that I just load, but I'm 'stopped' by the fact that in the end it's just an Hash, and I'd need to save the conf as json/yaml
[17:28:15] mensvaga: havenwood: so, that's interesting. That "spec.bindir" is indeed what was given to me by builder
[17:28:27] havenwood: ngw: You could Marshal it (or another serializer) the Hash and save it as a separate file or put it in at the end of the file with DATA __END__.
[17:29:17] mensvaga: json_file_name = File.expand_path(File.dirname(__FILE__)) + "/somemodule/file.json"
[17:29:34] havenwood: mensvaga: It's a common pattern to use "bin" as your executable dir. The Bundler folk like using "bin" for developer niceties and put executables in "exe". You can do it however you like. I use "bin".
[17:31:02] mensvaga: havenwood: any idea of how it came to be that 'exe' was chosen for bundler, when I'm running this on Linux?(!)
[17:31:10] havenwood: mensvaga: Pass #expand_path a second argument, and consider __dir__: File.expand_path(__dir__, 'foodie/foodie.erb')
[17:31:51] havenwood: mensvaga: That's what Bundler chose to name that directory. Most non-Bundler-generated gems use "bin" not "exe". Your choice.
[17:32:58] havenwood: mensvaga: I do it from scratch. Many folk make their own or use one of the many gems (including Bundler) which will generate a gem layout.
[17:34:20] havenwood: mensvaga: That way I think about every file and whether I need it and what should go in it. I've thought about generating but I kinda like starting with nothing.
[17:35:23] havenwood: mensvaga: Drop the .rb extension for your executable. You might also want to document the: chmod +x
[17:36:32] havenwood: mensvaga: Bundler's popularity is skewed here, because most people use it for non-generation purposes obviously: https://www.ruby-toolbox.com/categories/gem_creation
[17:36:51] mensvaga: My target audience is people who know that when they create a script that they need to run they should chmod +x .
[17:37:31] mensvaga: Also, for the purposes of being pretty verbose about it being a .rb, instead of, say, a .sh, I think I'll leave the extension on it.
[17:39:05] havenwood: mensvaga: that module name corresponds with the gem name ias-foodie and the file structure /lib/ias/foodie.rb
[17:40:06] havenwood: mensvaga: Do follow naming conventions or you'll be throwing users for a loop.
[17:41:08] mensvaga: See, I didn't know about the concept that calling it /lib/ias/foodie.rb would imply that there's a "Plugin for a gem named IAS"
[17:43:11] havenwood: mensvaga: or my little gem, digest-sip_hash adds another digest. that's not a plugin, but it's adding a new module to an existing, common digest module from the stdlib.
[17:43:57] havenwood: mensvaga: If you don't set the executable path, "bin" is the default. So I just list my executables: https://github.com/havenwood/digest-sip_hash/blob/master/digest-sip_hash.gemspec#L18
[17:45:07] havenwood: mensvaga: So actually you just need to remove a line to make where you put it work.
[17:46:19] mensvaga: * I don't understand the bigger picture. Currently thinking about other things.
[17:47:20] havenwood: mensvaga: On this line of your gem, you're changing the default to exe/: https://gitlab.com/theias/ruby_gem-ias-foodie/blob/master/IAS-Foodie.gemspec#L35
[17:47:46] havenwood: mensvaga: The line below it would also need to change. I like to just manually list my executables.
[17:49:58] mensvaga: OK, so, bundler is turning out to be non-ideal because of all of the stuff I have to change just to make the stuff usable.
[17:51:01] havenwood: I don't like that convention, but if you create an exe/ dir and put your binary there it'll *just work*.
[17:52:55] mensvaga: Also, it "forces" you to use git, by using 'git ls-files' in order to generate a file list.
[17:53:12] havenwood: mensvaga: You could see if you like this generator better: https://github.com/svenfuchs/gem-release#gem-bootstrap
[19:35:53] blackswan: i am trying to use rails in Perl. don't ask why, it's not safe for you to know.
[19:37:05] blackswan: it's complaining "Subroutine new redefined at (eval 324) line 518." for some deprecated OpenSSL classes
[19:38:48] blackswan: it's complaining this because it (meaning the Perl Inline::Ruby module) is trying to redefine 'new' for the Ruby class (i think), but it is also finding that the Ruby code it ran has defined a method named 'new'. so it's generating a string to be eval'ed by ruby that contains two different definitions of 'new'
[19:40:16] blackswan: it *does* override 'initialize', and the Inline::Perl isn't seeing that in the list of symbols it thinks got defined when the OpenSSL Ruby code was loaded.
[19:41:14] blackswan: is there some magic internally in the ruby code i should be looking for that might be taking the fact that this openssl code overrides the 'initialize' method and turning it into something that Inline::Perl is thinking is it overriding the 'new' method?
[19:41:47] blackswan: grepping for 'initialize' and 'new' would be difficult, so i thought i'd ask in the hopes that somebody who knows more about ruby internals would hear my plea and take pity on me
[19:42:10] blackswan: i mean, grepping would be easy finding the lines i'm looking for wouldn't be easy.
[19:42:55] blackswan: so something is different and i am trying to understand what it is so i can determine whether it is a problem and make it stop warning me about it.
[19:46:02] blackswan: it looks at the ruby namespace before and after it evaluates ruby code, and finds new definitions of methods and instance methods, and defines perl counterparts.
[19:47:08] blackswan: it's skipping a method named 'new' from ruby if it finds it as a class method but not if it finds it as an instance method.
[20:22:04] blackswan: it's because Digest::Base, Digest::Class, and Digest::Instance define an instance method named 'new'.
[20:30:31] flux__aeon: good morning. i'm new to rails and am having trouble grabbing a transaction ID returned from a Stripe call
[20:31:06] flux__aeon: lines 13 and 14... I am trying to get the charge id but I don't know how to output anything or even check what's int he charge object
[20:32:24] flux__aeon: https://stripe.com/docs/api/charges/create?lang=ruby according to the docs I should receive a response with "id"
[20:56:52] xco: Hi all. I’m getting a PG syntax error on this line with regex and have no idea how to deal with it. Will appreciate some help: https://gist.github.com/xcobar/04d902269107f5b385070bba6d3c4c38
[21:01:19] havenwood: xco: I see `SIMILAR TO` and `regexp_match` in the docs, but no plain `regexp`: https://www.postgresql.org/docs/11/functions-matching.html
[21:38:44] flux__aeon: so things end after a rescue? that's kind of odd. because i don't want my code to run unless a rescue isn't called
[21:40:32] havenwood: flux__aeon: you can ask `charge` what class it is with `charge.class`. it's `charge["id"]` because `charge` is a Hash.
[21:41:01] havenwood: flux__aeon: It can be handy for debugging to use #p to print an inspect an object: p charge
[21:41:37] flux__aeon: i thought somewhere else in this person's code they created a customer object
[21:42:57] havenwood: flux__aeon: 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
[21:43:58] flux__aeon: i don't know what any of that means. i know almost zero ruby. i only figured that part out because it's the same syntax as python loll
[21:45:00] havenwood: flux__aeon: Ruby ships with IRB, which is similar. You can jump out to irb from your code by putting a `binding.irb` on the line you want to be at.
[21:45:24] havenwood: flux__aeon: Try adding a `binding.irb` to a line in your code, then run the app.
[21:45:44] havenwood: flux__aeon: You'll see the app freeze when it gets to that line, then if you check your console you'll see an interactive terminal.
[21:46:40] havenwood: flux__aeon: To get a fancier interactive terminal, you can add `gem pry-rails` to your Gemfile and run: bundle
[22:09:47] Puppet`: So I am using pry just like I normally would use IRB, if I made an error in a method I was trying to make in pry is there a way I can go back and edit it or do I have to remake the whole method?