#ruby - 01 December 2017
« Back 1 day Forward 1 day »
[01:26:04] chiggins: Getting an error trying to setup active record and a schema with it. Seems like an error internal to active record though? https://gist.github.com/Chiggins/dbf3aea1bada355f36298cd3d62d05b1
[01:28:02] RickHull: I like this take on mixins: https://matt.aimonetti.net/posts/2012/07/30/ruby-class-module-mixins/
[01:30:16] ruby[bot1: Please join #RubyOnRails for Rails questions. You need to be identified with NickServ, see /msg NickServ HELP
[02:32:11] RickHull: do you mean: is it possible that Linux's OOM killer would kill only a ruby thread and not the entire process?
[02:49:46] RickHull: it looks like Linux OOM is process oriented https://www.kernel.org/doc/gorman/html/understand/understand016.html
[04:27:10] notmyrealname: Hi, anyone know some ways to read keyinput from a terminal that's not curses?
[04:30:24] havenwood: notmyrealname: https://ruby-doc.org/stdlib/libdoc/io/console/rdoc/IO.html#method-i-getch
[04:40:12] notmyrealname: havenwood: I found this gist https://gist.github.com/acook/4190379 and this gem https://github.com/acook/remedy that look interesting.
[04:54:34] havenwood: notmyrealname: if i recall correctly, io/console started as a gem but was adopted into the stdlib
[05:16:57] notmyrealname: havenwood: Thanks for the tip. I'm now going to dissappear into the mist. :)
[05:26:03] ruby[bot]: -b+b *!misterj@unaffiliated/veonik/bot/squishyj *!misterj@unaffiliated/veonik/bot/squishyj$#ruby-banned
[05:51:17] havenwood: riceandb1ans: HTTP.rb is among many nice gem options. Net::HTTP is of course in the stdlib.
[05:58:32] riceandb1ans: Also, does mechanize ever get any love or am I like the only weirdo left using it
[05:58:55] riceandb1ans: if there's something better for what it does/did please let me know, nokogiri makes me cry
[05:59:34] riceandb1ans: Ok, but anything that does the xpath stuff with less pain would make me day
[07:40:03] ruby[bot]: ruby[bot] kicked slegr: offense, see http://ruby-community.com/pages/user_rules
[10:00:59] TvL2386: hey guys, I'm having a String returned from a HP switch that has: 'Serial Number: \xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF Core Dump: YES'
[10:01:57] TvL2386: The encoding of this String is Encoding:ASCII-8BIT (whereas all other commands executed have encoding Encoding:UTF-8)
[10:02:49] TvL2386: when this string is dumped to json, I get an error: Encoding::UndefinedConversionError: "\xFF" from ASCII-8BIT to UTF-8
[10:04:01] TvL2386: it's probably due to newer firmware, I suspect a bug in the switch firmware, because an interactive ssh session also shows weird chars in that output
[10:05:04] TvL2386: I thought I would do output.gsub('\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF','*************') but it seems those chars are not matched
[10:21:04] ruby[bot]: check https://gist.github.com/apeiros/39acc5b486f932403638 - it might contain useful informations to solve your encoding problems
[10:24:13] adaedra: He's one of the founders, he wrote the document above, and is usually always here
[10:49:23] dminuoso: adaedra: But yeah, Rails has helpers in ActionView (!), and they're of low quality.
[10:51:56] dminuoso: I know radar has a gem for this, but it has a focus on precision rather than this "humanized form" moment.js provideds
[10:52:16] adaedra: Americans should not be programming software, they always forget there are other countries
[10:52:26] dminuoso: Whereas Radars would rather provide you with "4 months, 3 days, 17 hours [...] ago"
[10:54:34] dminuoso: You can configure it slightly to the accuracy that you want, check out the documentation.
[12:09:29] AlHafoudh: its only for logging progress percentage. i want to print the progress percent at least each 500ms lets say
[12:13:54] dminuoso: AlHafoudh: Do you need it in just one place, or do you want some abstraction to reuse in multiple places?
[12:16:55] dminuoso: Ive done some digging into this particular library https://github.com/socketry/timers
[12:17:09] dminuoso: It looks well written, and can easily be used to build some rate thottling around it
[12:52:01] Xano_: Hi! I have zero Ruby knowledge, but need to install a particular third-party Gem as part of a tool stack I am installing. The documentation recommends installing the Gems globally, causing all kinds of permission issues. What's a common approach to handle this? I assume there's another solution than running Gems with `sudo` :)
[12:52:23] Xano_: It's about https://docs.amazee.io/local_docker_development/pygmy.html to be specific
[13:51:06] caen23: hi, i was wondering what are good resources to get started with ruby. is the pickaxe fine for 2.4? i have programming experience (coming from c and python), and i'm not currently interested in rails. thanks!
[13:53:14] dminuoso: caen23: If you have good experience, you could just get the book "Eloquent Ruby" or perhaps "The Well Grounded Rubyist" which are currently the two most recommended books in this channel
[13:54:24] caen23: i did check out the list in the topic before asking, but it said twgr is for "introduction to programming in general" and that put me off as well
[13:57:33] dminuoso: caen23: The "introduction to programming" is basically just the first 4 pages or so.
[14:19:56] srandon111: hello all, where do i start with ruby ? can somebody advice me some good books about software design ?
[14:22:12] dminuoso: 14:53 dminuoso | caen23: If you have good experience, you could just get the book "Eloquent Ruby" or perhaps "The Well Grounded Rubyist" which are currently the two most recommended books in this channel
[14:25:27] srandon111: dminuoso: what about software design with classes... i mean do you generally use UML ?
[18:00:31] hockerfan11: Hello. I am trying to get the gem installation path in a users home directory programmatically. I seem to be able to get ALL the gem paths through 'gem env path', but can I get ONE of those paths without parsing this list?
[18:55:30] ruby[bot]: RickHull: # => undefined method `insersect' for ["b", "a", "w", "e", "a", "v", "e", "r"]:Array ...check link for more (https://eval.in/911680)
[18:56:08] ruby[bot]: dminuoso: # => wrong number of arguments (given 0, expected 1) (ArgumentError) ...check link for more (https://eval.in/911682)
[18:56:43] ruby[bot]: dminuoso: # => [["a", "w", "e", "v"], ["a", "w", "v", "e"], ["a", "e", "w", "v"], ["a", "e", "v", "w"], ["a", "v", ...check link for more (https://eval.in/911683)
[18:59:23] dminuoso: If you're using "bawaver" and "havenwood" you are just talking about ruby code, that's legit right?
[20:30:01] mikecmpbll: slightly strange question, but would it be possible to detect and log when a float is created that is NaN?
[20:30:18] mikecmpbll: i'm trying to trace where NaN is generated in some complex mathematical code.
[20:35:54] baweaver: Just throw a binding.pry in there whenever the condition is true or have it log out where it got hit
[20:36:13] mikecmpbll: it's actually bigdecimal that i'm working with, not float. just realised my earlier misspeaking but don't think it makes any diff
[20:37:38] dminuoso: RickHull: If FP is done natively and CR0.NE is set, then a CPU exception is emitted on unmasked fp exceptions.
[20:40:06] RickHull: boosh: https://ruby-doc.org/stdlib-2.1.1/libdoc/bigdecimal/rdoc/BigDecimal.html#method-c-mode
[20:54:22] RickHull: anyone play Traveller tabletop RPG? I have some questions for you in #ruby-offtopic please :)
[21:14:01] cr3: hi folks, I'm calling `sh "docker build ..."` in a Rakefile; the command returns an error message but copy/pasting the command on the shell runs fine. any ideas?
[21:17:46] RickHull: and it's generally better to call shell processes like: `sh command_name, arg1, arg2, ...`
[21:18:16] ruby[bot]: https://gist.github.com - Multiple files, syntax highlighting, even automatically with matching filenames, can be edited
[21:31:12] ule: correct if I'm wrong, but if I have two different object_ids, that means two different objects in memory right?
[21:32:18] ule: so if I use foo.keep_if instead of foo.select I'm gonna save memory since it mutates the object instead of creating a new one
[21:33:32] dminuoso: havenwood: Im afraid to answer, because I dont want to support mutating objects.
[21:34:13] havenwood: ule: Check your presumptions about memory usage and speed with metrics and benchmarks. Things may not be as you'd expect.
[21:34:32] havenwood: ule: Sometimes memory and speed matter less than predictability and testability.
[21:36:04] havenwood: ule: I'd suggest trying metrics and benchmarks with as realistic data as possible. Then see if the differences are important enough to be worth mutating.
[21:38:08] havenwood: "If a pure function mutates some local data in order to produce an immutable return value, is that ok?" ;-)
[21:39:13] dminuoso: ule: The way the code works, is that it scans the array, and moves items to the left if the match, resizing the array at the end.
[21:39:23] ule: if I mutate something that is the last statement from my method, knowing that Im gonna return that same data at the end, I'm actually saving 1 new object in memory and no risk of mutating since there is no more operations after that
[21:40:00] ule: dminuoso: 1 method call is 1 object, how about 100.000 method calls? 100.000 objects in memory
[21:40:51] ule: dminuoso: you mean, if we considerate that mutates is slower than creating a new object
[21:41:42] dminuoso: ule: Ignore benchmarks. Do you have code that suffers in performance, with the profiler telling you this is hot?
[21:42:07] dminuoso: If this is not a hot spot, we shouldn't be talking about this (i.e, use #select)
[21:44:25] ule: no. I just want to convince myself that if doesnt matter mutate or not since its the last statement in the method, 2 positive points on using keep_if instead of select is that it saves memory and its faster
[21:44:58] dminuoso: And it mutates. Mutating objects means you cant use this trivially in concurrency situations, and it makes code error prone.
[21:45:55] ule: but if the variable Im mutating is isolated inside a method scope, and its not an instance variable, then there is no concurrency
[21:46:39] ule: It was nice that my coleague bring this up review my code though. I got a chance to braindstorm better about all this
[21:49:35] dminuoso: And therein lies your problem. If you mutate arguments, this can trip anyone up in the entire callgraph above you that have access to the arra
[21:50:23] ule: thats all the method does. even if I use .select instead, the goal will be the same. Get rid of something and return it
[21:51:18] dminuoso: ule: Without seeing your code I can just assume that the array can come from multiple places. Lets assume I have some arr = [1,2,3], and I call some function writeToLog(arr), and that method happens to pass my array to yours, now my array has been mutated.
[21:55:28] clemens3: sometimes the caller explicitly wants the method to change the argument, sometimes it doesn't, use ! in the method name to indicate this.. if in doubt, create a new object and return that..
[21:56:59] s778: Hello! I'm wondering if anybody here has any suggestions. I've sent in a feature request for Ruby on the issue tracker, completele with a patch to help implement said feature, but I haven't received any reply in 14 days. Am I going about this the wrong way?
[21:57:08] dminuoso: That reminds me, my Q library needs to scan ObjectSpace for all classes, and undef_method any method ending in ! :D
[21:59:52] dminuoso: s778: I think something that touches diagnostics in this fashion is very likely to take time and discussion.
[22:01:28] s778: Oh, he just said "this seems like a decent idea" and gave some pointers on how it could be implemented
[22:03:02] dminuoso: s778: nobu is frequently the deciding factor in such matters, so if he thinks its a good idea that's also good :)
[22:09:52] dminuoso: But I like what you are doing. Finally they get a taste of "them speaking badly in our language" of their own!
[22:09:56] s778: For the PoC implementation I grab the filename and parse it using some library from sentry-raven, then read the function prototype that's defined on that file
[22:11:56] s778: No, it'd only work on argument errors instantiated by the Ruby. And even then only on methods called that exist in rubyland. For example, it wouldn't work on File.open().
[22:17:09] s778: Just tested it on procs by the way, doesn't work. Interestingly, the "receiver" becomes an integer, rather than a class?
[22:19:53] dminuoso: foo.rb:3:in `block in <main>': wrong number of arguments (given 0, expected 1) (ArgumentError)
[22:23:55] s778: I should be able to test that with something like `def foo(a:); end; foo()`, right?
[23:22:31] RickHull: dminuoso: haven't started it yet but going to https://www.youtube.com/watch?v=Fjv9GxPXtck RubyConf talk on static types in ruby
[23:29:33] RickHull: dunno yet, still chewing through other stuff, but I don't think you could call it ruby with a powerful type system
[23:30:44] RickHull: if you get all the type goodies you want, it would probably be something different from ruby