« Back to channel list

#ruby - 04 January 2019

« Back 1 day Forward 1 day »
[00:02:45] crankharder: has joined #ruby
[00:04:37] phaul: has joined #ruby
[00:06:49] Tempesta: has joined #ruby
[00:09:44] bmurt: has joined #ruby
[00:09:52] rubydoc: has joined #ruby
[00:16:07] jottr: has joined #ruby
[00:19:25] hutch: has joined #ruby
[00:21:12] tdy: has joined #ruby
[00:26:39] mikecmpbll: has joined #ruby
[00:43:32] conta: has joined #ruby
[00:47:40] uplime: has joined #ruby
[00:56:19] jottr: has joined #ruby
[00:57:12] Renich: has joined #ruby
[00:57:39] NingaLeaf: has joined #ruby
[01:00:13] Renich: has joined #ruby
[01:01:27] nowhere_man: has joined #ruby
[01:15:58] cthulchu_: has joined #ruby
[01:24:23] rkazak: has joined #ruby
[01:27:07] Ookma-Kyi: has joined #ruby
[01:35:37] chouhoulis: has joined #ruby
[01:41:33] Ookma-Kyi: has joined #ruby
[01:45:43] Nicmavr: has joined #ruby
[01:46:39] Ookma-Kyi: has joined #ruby
[01:47:21] orbyt_: has joined #ruby
[01:52:56] uplime: has joined #ruby
[01:53:02] hutch: has joined #ruby
[02:04:17] LightStalker: has joined #ruby
[02:06:37] esrse: has joined #ruby
[02:08:03] dviola: has joined #ruby
[02:10:16] davidw_: has joined #ruby
[02:33:45] tdy: has joined #ruby
[02:48:29] evdubs: has joined #ruby
[02:57:17] jottr: has joined #ruby
[03:02:18] MasterAsia: has joined #ruby
[03:16:30] cd: has joined #ruby
[03:24:34] crankhar1er: has joined #ruby
[03:33:28] hutch: has joined #ruby
[03:38:21] Renich: has joined #ruby
[03:40:26] Renich: has joined #ruby
[03:45:05] crankhar1er: has joined #ruby
[03:48:30] \void: has joined #ruby
[03:55:26] hutch: has joined #ruby
[03:57:55] crankhar1er: has joined #ruby
[03:59:43] sanscoeur: has joined #ruby
[04:01:44] orbyt_: has joined #ruby
[04:10:36] braincrash: has joined #ruby
[04:16:52] comet23: has joined #ruby
[04:17:09] comet23: how would i create a new hash value?
[04:17:14] comet23: this is what i'm trying :/
[04:17:30] comet23: https://repl.it/repls/NovelHomelyOctagons
[04:19:04] mozzarella: has joined #ruby
[04:19:13] mozzarella: how do you make a deep copy of an array?
[04:19:25] comet23: you don't]
[04:19:37] Radar: comet23: https://repl.it/repls/OtherPrizeServer
[04:19:57] Radar: comet23: use each_with_object, passing it a Hash where the default value for all keys in the hash is zero.
[04:20:10] Radar: >> h = Hash.new(0); h["a"]
[04:20:12] ruby[bot]: Radar: # => 0 (https://eval.in/1074344)
[04:20:21] comet23: mozzarella: sorry i wasn't replying to you
[04:20:26] comet23: i hit the wrong window :(
[04:20:32] Radar: Your issue is because your hash doesn't have that key set to any particular value.
[04:20:38] Radar: mozzarella: input and expected output plzkthx
[04:20:59] ruby[bot]: Radar: I don't know anything about mcve
[04:21:03] Radar: ruby[bot]: you never do.
[04:21:50] comet23: i'm not setting it on line 6 Radar ?
[04:21:52] ruby[bot]: Please provide a Minimal, Complete, and Verifiable example: https://stackoverflow.com/help/mcve
[04:22:11] Radar: comet23: only if the entire hash is empty.
[04:22:34] comet23: ae_chars = {}
[04:22:44] Radar: I just updated my example to remove the if statement entirely.
[04:22:45] comet23: ae_chars.empty? # => true
[04:23:04] davidw_: has joined #ruby
[04:23:06] Radar: comet23: yeah, but then you find the first character, increase the count for that and then what happens to ae_chars?
[04:24:21] Radar: comet23: is it then empty?
[04:25:01] comet23: !ae_chars[char]
[04:26:35] tiff: has joined #ruby
[04:27:02] comet23: Radar: you're a genius!
[04:27:06] comet23: thank you so much :D
[04:27:40] Radar: comet23: you're too kind
[04:29:26] comet23: mozzarella: look into this https://rubygems.org/gems/ruby_deep_clone
[04:31:17] comet23: https://stackoverflow.com/questions/17912476/why-isnt-there-a-deep-copy-method-in-ruby
[04:41:44] orbyt_: has joined #ruby
[04:55:33] memofun: has joined #ruby
[04:56:14] sauvin: has joined #ruby
[04:56:46] memofun: hi, im learning ruby. Im using IRB, when i execute this code 2.times {"hello"}, why at the end shows =>2
[04:57:09] WA9ACE: are you wanting to see the world "hello" printed to the screen?
[04:57:58] memofun: WA9ACE: yes, it shows the word hello 2 ties, but then shows =>2. What is the meaning of that
[04:58:16] jottr: has joined #ruby
[04:58:45] havenwood: memofun: Integer#yield returns self when a block is provided. So it just returns the integer you call it on.
[04:58:55] WA9ACE: that's the return type of the iterator
[04:58:57] Radar: memofun: When you call the times function on Ruby, it will evaluate the block that number of times. The function then returns itself.
[04:59:05] WA9ACE: what memofun said
[04:59:06] Radar: itself -> the object you called the function on
[04:59:25] havenwood: memofun: Try: 2.times.map {"hello"}
[04:59:44] WA9ACE: that will return an array with 2 strings of "hello"
[04:59:48] WA9ACE: instead of the number 2
[05:00:32] memofun: WA9ACE: havenwood thank you. Learning
[05:03:00] memofun: can you recommend a good tutorial to learn ruby?, my intention is to learn Ruby on Rails.
[05:03:01] houhoulis: has joined #ruby
[05:03:39] havenwood: memofun: Did you see the links I posted to you earlier?
[05:04:31] mr_rich101: has joined #ruby
[05:04:45] havenwood: memofun: The Rails docs are great to read once you've learned some Ruby.
[05:05:07] memofun: havenwood: no, can you share again please
[05:06:01] havenwood: memofun: Check here in the logs: https://freenode.irclog.whitequark.org/ruby/2019-01-03#23806605;
[05:10:46] memofun: havenwood: thank you
[05:10:53] havenwood: memofun: np
[05:40:31] hutch: has joined #ruby
[05:44:14] Ookma-Kyi: has joined #ruby
[05:44:58] Ookma-Kyi: has left #ruby: ()
[05:47:53] hell0h0la: has joined #ruby
[05:54:52] cnsvc: has joined #ruby
[06:04:46] patteh: has joined #ruby
[06:09:13] al2o3-cr: has joined #ruby
[06:11:37] havenwood: hell0h0la: hi
[06:12:53] al2o3-cr: &>> nh = {a:{b:{c:{d:{e:42}}}}}; hold = []; Marshal.load Marshal.dump(nh), -> v { hold << v; v }; hold.each &:freeze
[06:12:55] rubydoc: # => [:a, :b, :c, :d, :e, 42, {:e=>42}, {:d=>{:e=>42}}, {:c=>{:d=>{:e=>42}}}, {:b=>{:c=>{:d=>{:e=>42}}}}, ...check link for more (https://carc.in/#/r/5x1y)
[06:13:18] akaiiro3: has joined #ruby
[06:15:22] conta: has joined #ruby
[06:19:13] rippa: has joined #ruby
[06:32:01] kapil____: has joined #ruby
[06:33:23] patteh: has joined #ruby
[06:34:33] Puffball: has joined #ruby
[06:34:54] al2o3-cr: &>> nh = {a:{b:{c:{d:{e:42}}}}}; hold = []; Marshal.load Marshal.dump(nh), -> v { hold << v; v}; hold.each &:freeze; hold.map &:frozen?
[06:34:55] rubydoc: # => [true, true, true, true, true, true, true, true, true, true, true] (https://carc.in/#/r/5x1z)
[06:40:28] MasterAsia: has joined #ruby
[06:47:18] al2o3-cr: &>> Marshal.load Marshal.dump({a:114, b:117, c:98, d:121}), -> v { p v.chr if Integer === v }
[06:47:19] rubydoc: # => "r" ...check link for more (https://carc.in/#/r/5x21)
[06:47:39] al2o3-cr: ok, i'll stop now :p
[06:51:10] _whitelogger: has joined #ruby
[06:51:51] themsay: has joined #ruby
[06:52:52] themsay: has joined #ruby
[06:53:59] LadyElusive: has joined #ruby
[06:55:24] themsay: has joined #ruby
[06:55:56] aupadhye: has joined #ruby
[06:58:04] themsay: has joined #ruby
[06:59:09] jottr: has joined #ruby
[07:03:48] code_zombie: has joined #ruby
[07:07:37] themsay: has joined #ruby
[07:09:26] patteh: has joined #ruby
[07:12:30] aufi: has joined #ruby
[07:13:47] reber: has joined #ruby
[07:30:16] status402: has joined #ruby
[07:32:18] patteh: has joined #ruby
[07:38:31] status402: has joined #ruby
[07:47:19] dellavg_: has joined #ruby
[07:53:38] ruskie: has joined #ruby
[08:02:30] patteh: has joined #ruby
[08:07:35] clemens3: has joined #ruby
[08:16:00] Davey: has joined #ruby
[08:16:17] baweaver: Woo, put everything from 2018 together - https://medium.com/@baweaver/2018-in-review-3f619f26baca
[08:17:52] SeepingN: has joined #ruby
[08:20:27] snatcher: has joined #ruby
[08:23:34] snatcher: has left #ruby: ()
[08:50:12] comet23: i am having the hardest time grasping recursion
[08:50:24] comet23: https://repl.it/repls/DenseWhichApplications
[08:50:36] comet23: what i don't understand is why is it not returning 1 at the end
[08:57:17] status402: comet23: What the function is doing is essentially to keep running itself until some condition is met. That means that the 1 is just part of the "whole result", if that at all makes sense.
[08:57:28] comet23: no it doesn't
[08:57:47] comet23: it doesn't because it breaks my understanding of ruby returning the last thing that's evaluated
[08:57:47] discopatrick: has joined #ruby
[08:58:04] mutantkeyboard: has joined #ruby
[08:58:56] phaul: comet23 fwiw that method works fine here
[09:00:02] jottr: has joined #ruby
[09:00:59] status402: comet23: It actually is returning the last thing that's evaluated, but 1 isn't that.
[09:01:22] comet23: how is it not 1??
[09:02:47] status402: You start out by asking your function "is my number, n equal to 1?", which it's not so you multiply n by the result of calling your function yet again, this time with 4.
[09:04:09] vondruch: has joined #ruby
[09:04:50] status402: This continues until n actually is 1, at which point you start to gather up all the results of your function calls, so what you really have is a kind of pyramid shape of function calls.
[09:06:45] status402: I'd be making a lot more sense if I could draw this, honestly.
[09:06:58] mikecmpbll: has joined #ruby
[09:08:28] profetes: has joined #ruby
[09:11:01] status402: comet23: https://lucasfcosta.com/assets/factorial-calls.png is actually a much simpler way to visualize it than I had in mind. It shows you sort of the order of the calls.
[09:11:12] mutantkeyboard: Do you guys use Ruby for anything other than Rails?
[09:30:35] Aqo: has joined #ruby
[09:32:09] TheBrayn: mutantkeyboard: I'm using it for Puppet and general scripting
[09:32:36] TheBrayn: I haven't done much web development with it at all
[09:36:07] lxsameer: has joined #ruby
[09:44:23] phaul: mutantkeyboard: also inside the field of Ruby web development some ppl migrate to newer frameworks which either better fit how web development is changing, like sinatra, with single page apps or microservies, or have a cleaner design but still MVC like hanami.
[09:54:46] mutantkeyboard: paul I've used haa
[09:55:54] mutantkeyboard: But was more like a general question. I come from a lower-level development (C++ middleware services), and just decided to replace the previous Python glue code with Ruby, so that's where the question comes from
[10:51:02] tiff: has joined #ruby
[10:53:31] status402: has joined #ruby
[11:24:10] _whitelogger: has joined #ruby
[11:31:25] garyserj: has joined #ruby
[11:48:25] status402: has joined #ruby
[12:11:34] adac: has joined #ruby
[12:11:39] bak1an: has joined #ruby
[12:13:05] adac: Hi there! Is there a method to get an array out of a simple regex such as for example: (string1|string2|string3)?
[12:15:37] status402_: has joined #ruby
[12:17:35] canton7: adac, give us some sample input and sample output?
[12:18:55] adac: canton7, actually the regex is simply: (string1|string2|string3) and the output would be simply: [string1, string2, string3] I know I could remove chars and simply split but maybe there is a direct method that is used for such things?
[12:22:52] status402: has joined #ruby
[12:22:59] sonikspin: has joined #ruby
[12:23:06] canton7: what's the input?
[12:24:45] AJA4350: has joined #ruby
[12:25:27] status402: has joined #ruby
[12:25:59] adac: canton7, the imput is this regex string: (string1|string2|string3)
[12:28:42] status402: has joined #ruby
[12:29:15] up|ime: adac : and the string you're matching?
[12:31:10] canton7: you have two inputs: the regex, and the string the regex is applied to. You've only given us one of those two
[12:32:02] phaul: i think adac wants to interpret regexp as a string. regexp is not matched but rather is the data
[12:32:33] adac: yes from the regex I'd like to export the strings to an array
[12:32:48] adac: the 3 strings in that regex should become an array
[12:32:55] adac: of 3 items
[12:33:04] adac: 3 strings
[12:33:18] phaul: well, #to_s and #scan
[12:33:54] canton7: or something like 's[1..-2].split('|')' . Depends how much you want to check that the input is well-formed
[12:35:23] phaul: to_s seems to insert some junk.. so be careful. that aside why would you want to do this
[12:35:38] phaul: &>> /(a|b|c)/.to_s
[12:35:40] rubydoc: # => "(?-mix:(a|b|c))" (https://carc.in/#/r/5x50)
[12:36:54] canton7: ACTION has written regexes to parse regexes more times than he would have liked
[12:39:02] phaul: I think parsing regexes with regexes falls into the same category as parsing anything complex like html with regexes. simply dont
[12:39:22] adac: thanks for the hints!
[12:40:32] phaul: well, this might be an xy thing, you havent told us why you are doing such a thing
[12:40:35] ruby[bot]: it seems like you are asking for a specific solution to a problem, instead of asking about your problem. This often leads to bad solutions and increases frustration for you and those trying to help you. More: http://meta.stackexchange.com/a/66378
[12:42:01] adac: I think the solution to my issue is probably not to use regex in first place but define an array instead for such a simply case
[12:43:19] adac: I first was thinkink I cannot validate an array in ruby on rails
[12:43:30] adac: so I awanted to use a regex for validation
[12:43:44] up|ime: if you're dealing with forms they can send arrays of data and/or json post bodies
[12:52:05] szulak_: has joined #ruby
[13:13:41] MasterAsia: has joined #ruby
[13:39:51] bmurt: has joined #ruby
[13:41:29] Fusl: has joined #ruby
[13:41:44] sandelius: has joined #ruby
[13:42:55] sandelius: Hello everyone
[13:44:02] phaul: hi sandelius
[13:45:21] phaul: I heard it was windy over there, how are you holding up
[13:47:24] kapil____: has joined #ruby
[13:48:49] catbusters: has joined #ruby
[13:51:32] sandelius: phaul I live in the south so it sure was windy but not that bad like other countries have it sometimes.
[13:51:39] catbusters: Are example 1 and 2 equivalent? https://bpaste.net/show/713caf53d909
[13:52:01] Inline: has joined #ruby
[13:52:14] sandelius: catbusters { are mostly used when doing one-liner blocks
[13:52:44] rawrg: has joined #ruby
[13:53:07] catbusters: Ok. Getting a bit confused as I'm from JS land and the lack of braces and parens is putting me off balance
[13:53:31] phaul: equivalent but parser precedences might differ, you might need () around expressions to force the parser
[13:53:51] phaul: sometimes direct search and replace fails
[13:54:24] sandelius: catbusters try to wrap your head arounf that do/end is used for multi-line blocks and {/} for one-liners
[13:56:10] catbusters: And are these two examples also the same? https://bpaste.net/show/4be5bd06866f
[13:58:11] catbusters: What's the resources block inside the scope block? I mean, it looks like calling a function inside another function
[13:58:19] catbusters: Sorry for the noob questions
[13:59:48] sandelius: catbusters it's exactly that tho your're calling a method from the scoped context
[14:00:13] sandelius: it kinda works the same way as jsvascript
[14:02:01] agent_white: has joined #ruby
[14:03:20] catbusters: So I'd be able to define multiple resources blocks inside the scope block?
[14:09:46] jhass: sure, picture blocks as anonymous functions
[14:11:23] phaul: hi, jhass, sorry for jumping on you as soon as you appear :) can you please update carc.in to 2.6 for our bot, when you have time? (in your own time, no rush)
[14:11:43] jhass: as soon as it's out of testing @ https://www.archlinux.org/packages/extra/x86_64/ruby/
[14:12:11] jhass: that is if that happens tomorrow, will be without laptop for the week after
[14:12:35] phaul: ah, cool, thanks
[14:15:21] crankhar1er: has joined #ruby
[14:18:12] crankharder: has joined #ruby
[14:21:15] dviola: has joined #ruby
[14:24:23] krawchyk: has joined #ruby
[14:38:11] Puffball: has joined #ruby
[14:44:09] NingaLeaf: has joined #ruby
[14:44:45] Dbugger: has joined #ruby
[14:54:19] clemens3: has joined #ruby
[14:55:22] polishdub: has joined #ruby
[14:58:02] tdy: has joined #ruby
[15:13:25] comet23: has joined #ruby
[15:14:02] comet23: how do you create a new array with ordered nums?
[15:14:30] comet23: if x is 5 1...x => [1,2,3,4,5]
[15:15:02] comet23: or do you have to create a new array and iterate over it and append the current number into the array?
[15:15:33] mozzarella: > (1..5).to_a
[15:15:46] mozzarella: >> (1..5).to_a
[15:15:47] ruby[bot]: mozzarella: # => [1, 2, 3, 4, 5] (https://eval.in/1074629)
[15:16:08] mozzarella: comet23: is that what you want?
[15:16:22] comet23: thank you :D
[15:18:39] phaul: ruby[bot] , welcome back among the living!
[15:19:02] phaul: >> RUBY_VERSION
[15:19:03] ruby[bot]: phaul: # => "2.3.0" (https://eval.in/1074630)
[15:28:43] hiroaki: has joined #ruby
[15:30:11] conta: has joined #ruby
[15:39:38] Rapture: has joined #ruby
[15:39:53] vikaton: has joined #ruby
[15:40:35] ua: has joined #ruby
[15:47:59] spacesuitdiver: has joined #ruby
[15:48:51] phaul: has joined #ruby
[15:49:29] lucasb: has joined #ruby
[16:00:16] chouhoulis: has joined #ruby
[16:06:19] orbyt_: has joined #ruby
[16:21:12] ua: has joined #ruby
[16:27:02] profetes: has joined #ruby
[16:39:41] maryo: has joined #ruby
[16:40:03] dviola: nice to see 2.6.0 is out
[16:43:08] uplime: has joined #ruby
[16:44:23] \void: has joined #ruby
[16:45:27] despai: has joined #ruby
[16:49:17] tiff: has joined #ruby
[16:49:40] davidw_: has joined #ruby
[16:52:59] reber: has joined #ruby
[16:55:14] hutch: has joined #ruby
[17:00:23] Blaguvest: has joined #ruby
[17:20:47] orbyt_: has joined #ruby
[17:21:22] cthulchu_: has joined #ruby
[17:29:05] agent_white: has joined #ruby
[17:34:15] rubydoc: has joined #ruby
[17:39:28] despai: has joined #ruby
[17:48:06] phaul: has joined #ruby
[17:52:29] cthu|: has joined #ruby
[17:59:14] r29v: has joined #ruby
[18:00:57] ellcs: has joined #ruby
[18:02:03] clemens3: has joined #ruby
[18:02:41] mikecmpbll: has joined #ruby
[18:06:58] johnny56: has joined #ruby
[18:08:23] szulak_: has joined #ruby
[18:10:45] stephenplatz: has joined #ruby
[18:11:38] tiff: has joined #ruby
[18:11:40] sanscoeur: has joined #ruby
[18:22:04] Aqo: has joined #ruby
[18:29:58] chouhoulis: has joined #ruby
[18:30:45] NingaLeaf: has joined #ruby
[18:33:14] scrptktty: has joined #ruby
[18:37:53] Swyper: has joined #ruby
[18:41:16] SeepingN: has joined #ruby
[18:43:05] conta1: has joined #ruby
[18:43:24] tdy: has joined #ruby
[18:49:34] Rapture: has joined #ruby
[18:51:27] Xenosine: has joined #ruby
[18:51:45] Xenosine: has left #ruby: ()
[18:56:02] s3nd1v0g1us: has joined #ruby
[18:57:06] hutch: has joined #ruby
[18:58:03] sanscoeur: has joined #ruby
[19:17:37] NingaLeaf: has joined #ruby
[19:18:59] ua: has joined #ruby
[19:20:53] ivanskie: has joined #ruby
[19:22:26] ivanskie: i have a what i think is a fairly common problem that I haven't dealt with yet, trying to wrap my head around. thought I might ask for suggestions here.
[19:24:12] gnarmis: has joined #ruby
[19:25:09] bob_dino: has joined #ruby
[19:27:15] ivanskie: I'm using aws sdk, getting logs from cloudwatch logs. what i ended up doing was remap the messages hash to new hash like this: { timestamp: { message: '', instanceid: '' ...} since i will be collecting logs from several streams at once, i thought I'd push them all into a single hash, then do hash.keys.sort.each { |key| print hash[key].message } ( simplified for simplicity's sake)... so the issue i'm running into now, is when i
[19:27:15] ivanskie: refresh and get logs. it re-prints the old ones in addition to new ones, within the request limit.. of lets say 100 records. so refreshes, adds lets say 5 new lines, and 5 oldest lines dissapear, but all existing just get reprinted..
[19:27:43] ivanskie: so how can I check, and only print new records?
[19:32:46] havenwood: ivanskie: I don't quite follow your example code. Can you show a simplified version of what you're doing that run?
[19:33:50] ivanskie: probably not in a shirt time.
[19:34:18] cthulchu: has joined #ruby
[19:34:36] ivanskie: i think i need to keep track of "old" records. and when new ones come in, only deal with new records.
[19:34:40] havenwood: ivanskie: Your pseudo code has some inconsistencies and it's not clear which Hash you mean by `hash`.
[19:34:55] ivanskie: like array of epoch timestamps
[19:35:09] ivanskie: ah alright let me put some code together one sec
[19:41:34] quiliro: has joined #ruby
[19:46:36] ivanskie: havenwood https://dpaste.de/yZ0A
[19:48:01] ivanskie: on every request i get about 50 records from past few seconds.. then refresh using the "nextFordwardToken", which doesn't seem to be changing much, but thats a different issue alltogether.
[19:48:10] quiliro: hello...is there some newbie tutorial for using ruby to communicate with an FTDI device?
[19:48:19] ivanskie: so i'd like to just tail, and print only the new records, and not reprint old ones
[19:49:48] havenwood: ivanskie: Why `response.to_h` when `response` is already a Hash?
[19:50:05] ivanskie: i mean comes in as json
[19:50:32] ivanskie: hm yeah good point i guess
[19:50:43] havenwood: ivanskie: Where is `@events` defined?
[19:51:04] ivanskie: its blank at init. then i add to it on every request
[19:51:08] havenwood: ivanskie: This is a very hard example to follow, since it doesn't execute and references things that aren't here.
[19:51:11] ivanskie: so within that block
[19:51:27] havenwood: ivanskie: By "blank" do you mean it's an empty Hash?
[19:51:47] m27frogy: has joined #ruby
[19:55:11] bmurt: has joined #ruby
[19:55:38] rubydoc: has joined #ruby
[19:57:33] havenwood: quiliro: It looks like there are old gems callled ftdi and libftdi-ruby: https://github.com/Undev/libftdi-ruby
[19:57:49] havenwood: quiliro: https://github.com/hybridgroup/rubyserial
[19:58:48] quiliro: havenwood: thank you. i saw them but i do not understand...is there something tutorialish somewhere?
[19:59:23] havenwood: quiliro: What are you trying to do?
[20:00:06] quiliro: i want to communicate an avr via an ftdi to usb device to my computer
[20:00:30] quiliro: it must just send bits: 01100101001 etc
[20:01:51] quiliro: i have an idea of ruby already but it is very basic...perhaps it would be easier to learn though an exercise which involves what i need to achieve
[20:02:09] quiliro: -> send the data to the usb port
[20:02:12] havenwood: quiliro: I don't know of any tutorials.
[20:02:44] havenwood: quiliro: Maybe check: https://github.com/larskanis/libusb
[20:02:57] havenwood: quiliro: Dunno if this is relevant to what you're doing?: https://github.com/jmelkor/RubimC#some-interesting-idea
[20:03:29] bob_dino: has joined #ruby
[20:04:18] quiliro: havenwood: i even found this https://github.com/claudijd/serial-tools
[20:04:33] quiliro: but it is still too complicated for my level
[20:04:42] quiliro: let me check your last link
[20:04:45] havenwood: quiliro: Check the one I linked above, rubyserial.
[20:04:53] havenwood: quiliro: https://github.com/hybridgroup/rubyserial
[20:06:21] rubydoc: has joined #ruby
[20:09:32] quiliro: havenwood: that last link looks easier to understand and more up-to-date
[20:11:00] havenwood: ivanskie: Don't put timestamps past where you last checked in `@events` and they won't be there to print.
[20:11:22] ivanskie: how do you mean
[20:11:28] ivanskie: only add new ones?
[20:11:39] phaul: has joined #ruby
[20:11:50] baweaver: havenwood / phaul: https://twitter.com/keystonelemur/status/1081086171495620609
[20:12:01] baweaver: ( yes, I know it breaks some other things )]
[20:12:13] havenwood: ivanskie: Yup, unless you need them in `@events`, in which case only start iterating past the last seen timstamp
[20:12:16] baweaver: Also got a 2018 review done - https://medium.com/@baweaver/2018-in-review-3f619f26baca
[20:12:29] ivanskie: alright thank you :)
[20:13:33] tdy: has joined #ruby
[20:15:12] havenwood: baweaver: It's interesting there's NilClass#to_i, #to_h, #to_a, but no #to_int, #to_hash, #to_ary. I guess worry about masking bugs with implicit conversions?
[20:15:28] baweaver: Pretty much.
[20:15:35] brandonkal: has joined #ruby
[20:17:26] ivanskie: havenwood here's my actual code.. https://dpaste.de/zOv5#L157,158,159,163,165,166,167,168,169,170,171,172,173,174 i should be doing a comparison somewhere in there to determine only the new records. but not sure about the best way to do that. unless that means that the way i wrote that is already bad to begin with.
[20:17:55] ivanskie: within the block on lines 163-174
[20:20:12] havenwood: ivanskie: Put an if statement around line 158, checking if the timestamp is newer than last seen.
[20:32:26] ivanskie: that takes care of not adding duplicates. but my print block is still flawed, i'll have to do something similar there
[20:35:26] ivanskie: `if @events.keys.sorted[@events.size] < event['timestamp']` ?
[20:36:56] ivanskie: maybe add it to @new_events then only print @new_events
[20:39:11] ivanskie: or rather do that with timestamps.. only make list of new timestamps
[20:44:44] rubydoc: has joined #ruby
[20:45:04] phaul: has joined #ruby
[20:46:00] cthulchu: has joined #ruby
[20:52:58] cschneid: has joined #ruby
[20:58:27] hurricanehrndz: has joined #ruby
[21:02:20] cnsvc: has joined #ruby
[21:13:00] Scriptonaut: has joined #ruby
[21:13:36] Scriptonaut: have you guys noticed how in the ruby console, if you override an assignment method, it will always return whatever you assign it to, even if the method returns false?
[21:14:04] Scriptonaut: I have a method that's like: def receive_notifications=(flag); User.current.is_admin? && super(flag); end
[21:14:21] millerti: has joined #ruby
[21:14:53] Scriptonaut: in the console however, when User.current is a non-admin user, and I do: my_user.receive_notifications = true, the console prints "true" as the return value, even though I checked, and it's not true
[21:15:02] Scriptonaut: should I raise an error instead?
[21:15:07] cschneid: Does anybody have links to articles about tooling around ruby? We're using codeclimate, standardrb, and I'm looking at rufo for formatting - any others that people like? Trying to make sure a rapidly growing team stays relatively consistent
[21:17:12] mspo: rubocop?
[21:26:19] whathappens: has joined #ruby
[21:29:00] tomaw_: has joined #ruby
[21:35:12] despai: has joined #ruby
[21:41:15] conta: has joined #ruby
[21:46:57] tdy: has joined #ruby
[21:47:29] Mike11: has joined #ruby
[21:48:13] quiliro: has left #ruby: ()
[21:48:26] cschneid: mspo: standardrb is a set of rubocop rules - so that's included yep. Anything else to look at that will let junior devs focus on the behavior & tests rather than accidental complexity?
[21:49:59] LadyElusive: Scriptonaut: i think you're assigning a variable of the same name as the function, and assigning a variable returns what was assigned, thus true
[21:53:28] LadyElusive: also, the function you defined is "receive_notifications=" and not "receive_notifications"
[21:58:19] tdy: has joined #ruby
[21:58:19] havenwood: cschneid: You might take a look at Querly for things that come up: https://github.com/soutaro/querly#readme
[21:58:46] cschneid: @havenwood - oh cool, I like that
[21:58:48] spacesuit: has joined #ruby
[21:59:03] havenwood: cschneid: Or for non-code things, Goodcheck: https://github.com/sider/goodcheck#readme
[22:00:12] havenwood: cschneid: Sider have some other interesting tools: https://sider.review/
[22:02:19] Azure: has joined #ruby
[22:03:58] havenwood: cschneid: You might also consider reek: https://github.com/troessner/reek#readme
[22:04:22] cschneid: yeah, codeclimate has some set of those already - cyclomatic complexity and such.
[22:04:28] cschneid: I think it uses reek underneath
[22:04:57] havenwood: cschneid: Dependabot is handy, so each team doesn't need a person obsessed with following dep updates.
[22:05:05] havenwood: https://dependabot.com/
[22:05:32] havenwood: cschneid: Any Rails involved?
[22:05:45] cschneid: yep, that's the main app I'm worried about right now
[22:05:56] cschneid: rails_best_practices gem looked old when I last looked
[22:06:28] havenwood: cschneid: Yeah, it still has some interesting sections though. I tend to run it and largely disregard its output - but a few things worth looking at.
[22:06:50] havenwood: cschneid: Brakeman for sure.
[22:06:51] havenwood: cschneid: bundle-audit
[22:06:56] tiff: has joined #ruby
[22:07:58] havenwood: cschneid: the bullet gem for N+1 queries and unnecessary eager loading
[22:08:12] nickjj_: has joined #ruby
[22:08:30] havenwood: cschneid: ah, missing indexes is one nice rails_best_practices thing
[22:08:49] havenwood: that matters soo mcuh
[22:09:22] mustmodify: has joined #ruby
[22:09:26] mustmodify: I'm having brain problems.
[22:09:33] cschneid: of for sure. I actually work at scoutapp.com - an APM. So performance, especially db, is what we do :)
[22:10:01] mustmodify: I want an iterator that provides the n and the n+1st elements of an array
[22:10:09] mustmodify: is that a thing? I guess I could write one...
[22:10:16] havenwood: cschneid: hah, I was a Scout customer on Heroku
[22:10:20] havenwood: cschneid: Nice stuff!
[22:10:49] havenwood: mustmodify: each_cons
[22:11:03] cschneid: havenwood: And thank you for the ton of linters I get to go track down and implement!
[22:11:07] havenwood: cschneid: AccessLint for accessibility CI
[22:11:47] havenwood: https://github.com/accesslint/accesslint.js
[22:11:54] havenwood: https://www.accesslint.com/
[22:12:05] mustmodify: havenwood: Oh blah, I was just writing it. Spoil my fun!
[22:12:10] mustmodify: thanks I'll check it out.
[22:12:46] mustmodify: havenwood: Hunh. I would never have found that. Thanks.
[22:12:49] havenwood: mustmodify: hah, np - each_cons(2) for doubles
[22:12:56] mustmodify: has left #ruby: ()
[22:13:56] nickjj: has joined #ruby
[22:15:49] Scriptonaut: LadyElusive: no I overrode the receive_notifications= method. THen I call super inside of it. The method returns false, I've tested it, but for some reason the console (only in the console, not when it runs anywhere else) short-circuits and displays the return value as whatever you pass to it. With a normal assignment method this is expected behavior, but I overrode the method and changed how it worked
[22:16:29] Scriptonaut: I'll gist the actual code
[22:17:01] gix: has joined #ruby
[22:17:41] orbyt_: has joined #ruby
[22:19:25] Scriptonaut: https://gist.github.com/robins35/8e20263ad98243a0d9edbfc2fe8f8370
[22:19:30] Scriptonaut: that's odd behavior
[22:22:12] Scriptonaut: I made another gist that demonstrates the weird behavior: https://gist.github.com/robins35/ddd8616f05bfaa256292ab1d559e0c46
[22:25:23] hutch: has joined #ruby
[22:26:47] nickjj: has joined #ruby
[22:28:23] spacesuitdiver: has joined #ruby
[22:29:21] despai: has joined #ruby
[22:35:24] Eiam: in console whats your staff.first.is_admin? value
[22:36:00] CrazyEddy: has joined #ruby
[22:37:29] Eiam: your first line makes it sound like that value is false, since line 3 shows false. if is_admin is false, the next call will be false && super(true) which can only return false
[22:37:33] Eiam: Scriptonaut: ^
[22:38:39] orbyt_: has joined #ruby
[22:38:49] Eiam: so then its false && super(true) as the return value on line 4, which we already established must be false because it says false in your output.
[22:39:29] Scriptonaut: Eiam: exactly
[22:39:33] Scriptonaut: that's why I'm confused
[22:39:36] Eiam: right so I don't get the bug
[22:39:38] Scriptonaut: why is the console displaying true, when it's false
[22:39:40] Eiam: its working exactly as the code says
[22:40:12] Scriptonaut: no it's not, look at line 6
[22:40:16] Scriptonaut: it returns true
[22:40:17] Eiam: oh, something to do with how irb echos statements or something
[22:40:26] Eiam: i don't think thats the return value of your statement
[22:40:47] Scriptonaut: when I do: ret_val = (gu.receive_direct_message_alerts = true), ret_val is assigned true
[22:41:14] Scriptonaut: only in the console though, when I run it on unicorn or even just through the interpreter it returns false
[22:42:15] Scriptonaut: https://gist.github.com/robins35/3b0e74d853002b3912e322ec8b17cdf2
[22:43:37] Eiam: whats the implementation of receive_direct_message_alerts
[22:44:22] baweaver: ACTION wanders in
[22:44:54] Scriptonaut: Eiam: it's a cp_typed_hash on an ActiveRecord 2 model
[22:45:11] Scriptonaut: the method I wrote is to override the setter to prevent non-admins from having that setting set to true
[22:45:12] Eiam: i mean do you have receive_direct_message_alerts and receive_direct_message_alerts=
[22:45:29] baweaver: ACTION kinda thinks this sounds like Rails
[22:45:40] Scriptonaut: baweaver: it's not
[22:45:57] Eiam: because it looks like you are calling two different implementations and wondering why each has its own return value
[22:46:02] Scriptonaut: Eiam: I explicitly wrote the setter, the getter was defined by cp_typed_hash
[22:46:04] Eiam: but I only see one implementation, receive_direct_message_alerts=
[22:46:11] Scriptonaut: Eiam: yes, I wrote that
[22:46:18] Scriptonaut: and then call super, to the setter that was defined previously
[22:46:23] Scriptonaut: method overriding
[22:46:35] Scriptonaut: I only call super if the user is an admin though
[22:47:07] Scriptonaut: this is an issue with irb, the code is working as it should, it's just that in irb the return value is true when it should be false
[22:47:27] Scriptonaut: I wonder if it's a bug in old irb, this is ruby 1.8.7
[22:48:33] Eiam: okay... what I'm saying is you could be calling "methodA" and it gives you false. later you call "methodB" and it gives you true, then you again call "methodA" and it gives you false again, which is expected...
[22:49:36] Eiam: receive_direct_message_alerts and receive_direct_message_alerts= aren't the same method , they could be defined totally different
[22:50:02] Scriptonaut: I gisted a console session, I am not confusing the getter and setter
[22:50:21] Scriptonaut: I just recreated it in irb with a test class: https://gist.github.com/robins35/bb3dbd2dcc13a72b9d2a39ba1a73fee3
[22:50:30] Scriptonaut: there, that's plain ruby, no activerecord, no method overriding
[22:50:36] Scriptonaut: it still has the issue
[22:50:58] Scriptonaut: as you can see, on line 6, the method x= should always return false
[22:51:06] Scriptonaut: however on line 15 it returns true
[22:51:42] Scriptonaut: when I do: t.x = "foo bar", it returns "foo bar"
[22:52:06] Scriptonaut: I'm gonna try in ruby 2.5 and see if the issue is still there
[22:53:57] drale2k_: has joined #ruby
[22:54:05] Scriptonaut: hmm, still happens with ruby 2.5.1. It must just be the way the console is written. I always thought that the => in the console was supposed to denote the return value, but when the method ends with a '=', it returns the RValue no matter what
[22:54:15] Eiam: it behaves the same on 2.3.7
[22:54:53] Scriptonaut: this was my 2.5.1 run: https://gist.github.com/robins35/f446778a0e5dec454977bf035adf7dde
[22:55:05] Scriptonaut: oh well, it's not a big deal, the code works. I just thought that was weird
[22:55:57] rubydoc: has joined #ruby
[22:56:04] Eiam: if you split your assignment out into its own line
[22:56:07] Eiam: the behavior will change
[22:56:27] Eiam: i thought assignment in comparisons were frowned upon
[22:56:48] Eiam: on line 6 if you set @x = flag, then do false && @x you'll see it shifts
[22:57:33] Scriptonaut: well that would change the behavior because that's totally different code. The assignment in your example wouldn't be dependent on the first argument to &&
[22:57:42] Scriptonaut: that would assign @x to flag no matter what
[22:57:55] Scriptonaut: I came up with an even simpler example
[22:57:57] Scriptonaut: def foo=(bar); false; end
[22:58:08] Scriptonaut: f = true # This returns true
[22:58:13] Scriptonaut: foo = true **
[22:58:34] Scriptonaut: even though the method :foo= just returns false
[22:58:57] Eiam: oh you are counting on the early exit to avoid the assignment
[22:59:46] Eiam: Scriptonaut: yeah, that is interesting
[22:59:48] Scriptonaut: ya, pretty much. In my actual program I'm not doing condition && foo = bar, I'm just calling super(flag)
[22:59:51] Eiam: i don't know why you are seeing that behavior in console
[23:00:42] phaul: has joined #ruby
[23:02:00] Scriptonaut: this seems like it might be related https://bugs.ruby-lang.org/issues/2050
[23:03:19] Scriptonaut: someone wrote a blog post about it https://jeremy.wordpress.com/2010/09/03/assignment-like-methods-and-the-returned-value-in-ruby/
[23:05:57] Nicmavr: has joined #ruby
[23:06:26] hutch: has joined #ruby
[23:07:24] yxhuvud: has joined #ruby
[23:12:08] waheedi: has joined #ruby
[23:12:22] waheedi: is rubygems.org down for fetching gems or versions?
[23:12:34] waheedi: or its a deployment on a late friday
[23:13:06] waheedi: or it could be my poor internet connection, timing out :)
[23:13:29] waheedi: Exception `Gem::RemoteFetcher::UnknownHostError' at /usr/local/rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/rubygems/remote_fetcher.rb:276 - timed out (https://rubygems.org/api/v1/dependencies)
[23:14:07] Paraxial: has joined #ruby
[23:15:22] Scriptonaut: I just bundled fine, I wonder if it cached the locations of my gems since they're already downloaded though.
[23:16:03] havenwood: waheedi: Seems up to me.
[23:17:07] waheedi: I first thought its a bundler issue, so tried manually installing gems, and it worked
[23:17:40] waheedi: then went back to try again after few minutes with bundler, and it failed again, then when tried again manually it failed as well.
[23:18:07] waheedi: so its either timing out very quickly or
[23:18:23] waheedi: it hate my icmp tunnel for some reason
[23:18:29] Scriptonaut: there are various rubygem servers right?
[23:18:36] Scriptonaut: I wonder if the one you usually use is down
[23:18:44] waheedi: i use rubygems.org
[23:18:56] Scriptonaut: same, I mean I think there are various physical servers, depending on your location
[23:19:11] waheedi: Scriptonaut: do I have to load balance them manually too :)
[23:19:27] waheedi: yeah they are dns fail over or based on location, for sure
[23:19:47] Scriptonaut: ya, I've never had rubygems go down on me
[23:19:51] Scriptonaut: but it could be
[23:20:17] waheedi: is the one I'm calling atm
[23:20:19] Scriptonaut: https://status.rubygems.org/
[23:20:25] Scriptonaut: did you just ping that to get it?
[23:20:29] waheedi: the website seems to be fine
[23:20:44] Scriptonaut:
[23:21:06] cthulchu: has joined #ruby
[23:21:20] Scriptonaut: under ANSWER SECTION I got 4 rubygems.orgs, one of them is that one you are hitting
[23:21:34] Scriptonaut: they all have the same values other than IP
[23:21:39] trbh: has joined #ruby
[23:21:57] Scriptonaut: I'm hitting the first one on the list, the 128 one you're hitting is the 3rd one
[23:22:09] waheedi: I can open linked just fine but https://status.rubygems.org/ does not appear to open on my end
[23:22:18] waheedi: ERR_TIMED_OUT
[23:22:29] Scriptonaut: it shows me that everything is operational, I'm hitting it fine
[23:22:35] Scriptonaut: Try hitting that:
[23:22:49] Scriptonaut: oh it doesn't like it when I try to hit it by ip
[23:23:06] waheedi: sure it does not
[23:23:19] phaul: has joined #ruby
[23:23:23] rubydoc: has joined #ruby
[23:23:28] waheedi: the web server is relaying apps based on their host names :)
[23:23:48] Scriptonaut: microservices
[23:23:58] waheedi: thats the buzz word
[23:24:03] waheedi: i don't use it
[23:24:18] waheedi: but its cool
[23:24:37] sanscoeur: has joined #ruby
[23:25:50] RougeR: has joined #ruby
[23:27:17] waheedi: it seems timing out is too short for low speed connections like mine
[23:27:45] Scriptonaut: do you have a vps or something you could test it out on
[23:27:53] Scriptonaut: some remote server you could try pulling in rubygems from
[23:27:56] waheedi: yeah i already did, it works fine
[23:28:05] Scriptonaut: ah ok, must just be your connection
[23:28:22] waheedi: well, I hope so
[23:33:25] cthulchu: will JSON.pretty_generate prettify other object that are not hashes?
[23:35:12] waheedi: so if they are not hashes, what they are?
[23:35:47] cthulchu: well like would it pretty print an object like puts_r or what it's called
[23:35:56] cthulchu: including :
[23:36:06] cthulchu: I think it'll print : just fine
[23:36:09] cthulchu: I tested that
[23:36:31] Inline: has joined #ruby
[23:36:58] planigan: has joined #ruby
[23:41:31] Scriptonaut: cthulchu: you just mean to read? You could use awesome_print
[23:41:39] Scriptonaut: that will pretty print all kinds of things
[23:41:45] bob_dino: has joined #ruby
[23:41:47] Scriptonaut: what's puts_r
[23:41:55] cthulchu: tell me I don't need a gem for it
[23:42:02] Scriptonaut: it's a tiny gem though iirc
[23:42:09] Scriptonaut: I always put awesome_print in my dev dependencies
[23:42:27] Scriptonaut: you could also download it and then just require it as needed I think
[23:53:26] johnny56_: has joined #ruby