« Back to channel list

#ruby - 14 September 2018

« Back 1 day Forward 1 day »
[00:00:24] havenwood: mememeIAMMEE: The patterns `Hash.new(0)` and `Hash.new { |h, k| h[k] = []` are the most common other than a simple Hash literal `{}`.
[00:00:34] chouhoulis: has joined #ruby
[00:00:45] havenwood: mememeIAMMEE: Just know that if you lookup a Hash key that doesn't exist, it'll be `nil` by default.
[00:00:56] mememeIAMMEE: So would Hash.new(0) make the hash dynamic by default?
[00:01:10] havenwood: >> Hash.new(0)[:example]
[00:01:16] ruby[bot]: havenwood: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[00:01:18] havenwood: >> Hash.new(0)[:example]
[00:01:24] ruby[bot]: havenwood: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[00:01:26] havenwood: the bot is donw
[00:01:36] havenwood: Hash.new(0)[:example] #=> 0
[00:01:37] mememeIAMMEE: You mean dumb
[00:01:54] havenwood: h = Hash.new 0; h[:example] += 2; h[:example] #=> 2
[00:02:24] havenwood: mememeIAMMEE: ^ it's a pattern for zero as the default value for an undefined key
[00:02:38] havenwood: mememeIAMMEE: the same for an Array isn't what people usually want, Hash.new([])
[00:02:56] havenwood: mememeIAMMEE: because that Array is the value for *every* key, that exact Array, not a new one for each missing key
[00:03:27] havenwood: this makes a *fresh* Array for each default key value: Hash.new { |h, k| h[k] = [] }
[00:03:54] havenwood: mememeIAMMEE: But yeah, you don't have to use default Hash values. You can just ensure they're something there before shoveling if you prefer..
[00:04:32] havenwood: {}[:no_default] #=> nil
[00:04:48] havenwood: {}[:no_default] += 1 #!> ERROR
[00:05:18] havenwood: Hash.new(0)[:default] += 1 #=> 1
[00:05:27] havenwood: mememeIAMMEE: make sense?
[00:06:04] chouhoulis: has joined #ruby
[00:07:01] mememeIAMMEE: does Hash.new { |h, k| h[k] = [] } not create a lot of empty keys?
[00:08:24] havenwood: >> h = Hash.new { |h, k| h[k] = [] }; h.default_proc
[00:08:30] ruby[bot]: havenwood: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[00:08:33] mememeIAMMEE: I can effectively use it in my code now, but I do not have a full understanding of it.
[00:08:36] havenwood: mememeIAMMEE: That block is setting the default proc for a missing key.
[00:08:47] havenwood: => #<Proc:...>
[00:09:09] havenwood: >> h = Hash.new { |h, k| h[k] = [] }; h # see, it's empty
[00:09:12] mememeIAMMEE: What does proc mean
[00:09:14] ruby[bot]: havenwood: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[00:09:22] mememeIAMMEE: Hash.new { |h, k| h[k] = [] }
[00:09:30] mememeIAMMEE: Hash.new { |h, k| h[k] = [] };
[00:10:00] mememeIAMMEE: Oh, I see. Ill brb at work, must act busy for a minute.
[00:10:24] havenwood: mememeIAMMEE: A proc is like a little function object that encloses the context. I'd not worry about it for your interview.
[00:10:47] havenwood: >> >> add_one = proc { |n| n + 1 }; add_one.call 42 # mememeIAMMEE this is a proc
[00:10:53] ruby[bot]: havenwood: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[00:11:03] havenwood: I gotta stop using the bot.
[00:11:23] havenwood: mememeIAMMEE: Procs are neat. Come back and ask the channel when you have time!
[00:11:34] chouhoulis: has joined #ruby
[00:13:32] bhaak: has joined #ruby
[00:13:45] DTZUZO: has joined #ruby
[00:16:53] chouhoulis: has joined #ruby
[00:18:03] chouhoulis: has joined #ruby
[00:23:27] chouhoulis: has joined #ruby
[00:26:44] eckhardt: has joined #ruby
[00:28:25] AKPWD: has joined #ruby
[00:28:48] chouhoulis: has joined #ruby
[00:29:55] mememeIAMMEE: I have returned
[00:30:22] mememeIAMMEE: Actually wait, I think I want coffee.
[00:34:13] chouhoulis: has joined #ruby
[00:34:35] orbyt_: has joined #ruby
[00:36:46] mememeIAMMEE: Now I'm back, with coffee. So havenwood are you still here?
[00:38:42] mememeIAMMEE: Alright, can somebody explain procs to me? I hear they are neat.
[00:38:55] chouhoulis: has joined #ruby
[00:46:28] ramfjord: has joined #ruby
[00:51:39] brandoncc: has joined #ruby
[00:52:10] za1b1tsu: has joined #ruby
[00:54:03] ZzZombo: has joined #ruby
[00:56:41] gnufied: has joined #ruby
[01:00:14] KramerC_: has joined #ruby
[01:00:52] Miron_: has joined #ruby
[01:00:57] Phage: has joined #ruby
[01:02:10] swistak35: has joined #ruby
[01:02:35] Guest48993: has joined #ruby
[01:03:36] fribmendes: has joined #ruby
[01:03:36] gsingh93: has joined #ruby
[01:03:40] woodruffw: has joined #ruby
[01:03:47] cpallares: has joined #ruby
[01:04:34] khomesh24: has joined #ruby
[01:04:50] c0san0stra: has joined #ruby
[01:04:58] Exagone313: has joined #ruby
[01:05:16] endofline: has joined #ruby
[01:05:19] shoogz-: has joined #ruby
[01:06:02] lxsameer: has joined #ruby
[01:13:53] varesa: has joined #ruby
[01:14:53] mememeIAMMEE: Is there a more efficient method of doing this?
[01:14:53] mememeIAMMEE: def last_digit(int) int.to_s.chars.to_a[-1].to_i end
[01:15:17] mememeIAMMEE: https://dpaste.de/2NXx
[01:17:01] mememeIAMMEE: It was the first idea that came to mind.. Dunno how efficient converting back and forth 3 times is though
[01:17:19] al2o3-cr: mememeIAMMEE: int.digits.first
[01:18:15] mememeIAMMEE: But im looking for last?
[01:18:16] ramfjord: has joined #ruby
[01:20:07] al2o3-cr: Integer#digits returns an array of integers in reverse order.
[01:20:18] apeiros: has joined #ruby
[01:21:23] mememeIAMMEE: How could I convert the int to_a in normal order?
[01:21:54] mememeIAMMEE: int.to_a doesn't seem to work
[01:23:48] orbyt_: has joined #ruby
[01:24:43] al2o3-cr: mememeIAMMEE: why do you want it in normal order?
[01:25:23] mememeIAMMEE: I'm just trying to shovel a lot of information before interview, just in case i need it.
[01:25:49] mememeIAMMEE: Never used Ruby, trying to learn it in 3 days
[01:26:02] mememeIAMMEE: Actually 4, even better :)
[01:27:01] mememeIAMMEE: Lunch break, be back.
[01:34:52] Freshnuts: has joined #ruby
[01:42:07] pskosinski: has joined #ruby
[01:51:38] za1b1tsu: has joined #ruby
[01:54:24] cpruitt: has joined #ruby
[01:55:43] jottr: has joined #ruby
[02:04:12] esrse: has joined #ruby
[02:13:25] jcalla: has joined #ruby
[02:13:36] justizin: has joined #ruby
[02:16:19] orbyt_: has joined #ruby
[02:24:33] herbmillerjr: has joined #ruby
[02:43:39] kotepillar_: has joined #ruby
[02:55:09] akemot: has joined #ruby
[02:56:08] cpruitt: has joined #ruby
[03:02:20] Raboo_: has joined #ruby
[03:02:38] arescorpio: has joined #ruby
[03:04:44] arooni: has joined #ruby
[03:05:21] kotepillar_: has joined #ruby
[03:05:21] duckpuppy: has joined #ruby
[03:06:40] lxsameer: has joined #ruby
[03:09:08] JasonO: has joined #ruby
[03:09:21] dan64: has joined #ruby
[03:10:49] braincrash: has joined #ruby
[03:35:07] Sigyn: has joined #ruby
[03:37:00] amelliaa: has joined #ruby
[03:39:44] za1b1tsu: has joined #ruby
[03:44:10] duderonomy: has joined #ruby
[03:46:49] dan64: has joined #ruby
[03:51:03] dviola: has joined #ruby
[03:53:59] im0nde: has joined #ruby
[03:56:41] jottr: has joined #ruby
[04:09:01] cpruitt: has joined #ruby
[04:22:30] cpruitt: has joined #ruby
[04:23:17] tristanp: has joined #ruby
[04:28:47] agent_white: has joined #ruby
[04:33:20] agent_white: has joined #ruby
[04:36:31] Ameisen: has joined #ruby
[04:46:08] dellavg_: has joined #ruby
[04:56:34] za1b1tsu: has joined #ruby
[05:00:10] cpruitt: has joined #ruby
[05:03:18] brandoncc: has joined #ruby
[05:06:21] sauvin: has joined #ruby
[05:10:04] tristanp: has joined #ruby
[05:19:11] reber: has joined #ruby
[05:25:27] brandoncc: has joined #ruby
[05:30:52] brandoncc: has joined #ruby
[05:32:30] Sigyn: has left #ruby: ("Leaving the channel (no spam or action taken for 30 days.) /invite Sigyn #ruby again if needed")
[05:35:58] dan64: has joined #ruby
[05:36:20] kapil___: has joined #ruby
[05:40:13] cpruitt: has joined #ruby
[05:51:10] tdy: has joined #ruby
[05:56:02] brandoncc: has joined #ruby
[05:57:27] jottr: has joined #ruby
[06:05:22] aupadhye: has joined #ruby
[06:07:40] cpruitt: has joined #ruby
[06:10:50] tristanp: has joined #ruby
[06:12:23] snickers: has joined #ruby
[06:20:53] MoritaShinobu: has joined #ruby
[06:41:02] madhatter: has joined #ruby
[06:45:08] aufi: has joined #ruby
[06:50:17] marz_d`ghostman: apeiros: Why can I declare a module, a method inside it and invoke the inject(:+) method directly? I though I need to include Enumerable first? https://gist.github.com/marzdgzmn/e804d65ca37bc98684c912803d9df0c7
[07:04:10] asphyxia: has joined #ruby
[07:07:08] cpruitt: has joined #ruby
[07:13:42] jottr: has joined #ruby
[07:15:25] Tempesta: has joined #ruby
[07:16:09] cpruitt: has joined #ruby
[07:17:48] za1b1tsu: has joined #ruby
[07:18:43] yohji: has joined #ruby
[07:19:13] Dark_Arc: has joined #ruby
[07:22:11] sysvalve: has joined #ruby
[07:35:47] za1b1tsu: has joined #ruby
[07:38:56] aufi: has joined #ruby
[07:45:47] cpruitt: has joined #ruby
[07:45:52] akem: has joined #ruby
[07:48:42] za1b1tsu: has joined #ruby
[07:50:49] c0ncealed2: has joined #ruby
[07:59:27] cgfbee: has joined #ruby
[08:07:12] lxsameer: has joined #ruby
[08:14:41] johnny56: has joined #ruby
[08:16:09] cpruitt: has joined #ruby
[08:30:21] RougeR: has joined #ruby
[08:43:18] agit0: has joined #ruby
[08:48:39] NL3limin4t0r_afk: marz_d`ghostman: I guess it depends where you include your module. If Enumerable is already included this works without issues.
[08:49:18] NL3limin4t0r: Otherwise an exception will be raised.
[08:49:23] NL3limin4t0r: >> module Sumable; def sum; inject(:+); end; end; class Foo; include Sumable; end; Foo.new.sum
[08:49:29] ruby[bot]: NL3limin4t0r: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[08:49:40] Beams: has joined #ruby
[08:49:55] NL3limin4t0r: #=> NoMethodError: undefined method `inject' for #<Foo:0x00556e3c944238>
[08:50:40] NL3limin4t0r: ACTION sighs
[08:50:53] NL3limin4t0r: ruby[bot] has a lot of issues lately
[08:52:11] ShekharReddy: has joined #ruby
[08:54:01] Nicmavr: has joined #ruby
[08:55:54] za1b1tsu: has joined #ruby
[08:57:24] hogetaro: has joined #ruby
[09:16:05] za1b1tsu: has joined #ruby
[09:17:01] cgfbee: has joined #ruby
[09:19:19] tuor: has joined #ruby
[09:20:45] chichou: has joined #ruby
[09:31:08] graphene: has joined #ruby
[09:38:11] cgfbee: has joined #ruby
[09:41:50] leitz: has joined #ruby
[09:51:24] ams__: has joined #ruby
[09:56:32] aupadhye: has joined #ruby
[10:00:28] vqrs: has joined #ruby
[10:05:38] elphe: has joined #ruby
[10:13:41] tristanp: has joined #ruby
[10:18:47] charlielor: has joined #ruby
[10:21:32] charlielor: has joined #ruby
[10:32:42] elphe: has joined #ruby
[10:37:34] cgfbee: has joined #ruby
[10:38:50] charlielor: has joined #ruby
[10:45:24] jammanbo: has joined #ruby
[10:47:37] jammanbo: Is there anyone using the Grape gem that can point me to an example of an endpoint that serves both JSON and HTML?
[10:52:57] aupadhye: has joined #ruby
[11:05:26] DTZUZO: has joined #ruby
[11:08:36] ChrisBr: has joined #ruby
[11:10:20] vqrs: has joined #ruby
[11:11:12] Paraxial: has joined #ruby
[11:11:28] AJA4350: has joined #ruby
[11:12:56] sonOfRa: has joined #ruby
[11:13:24] apeiros: has joined #ruby
[11:20:27] Paraxial: has joined #ruby
[11:21:29] Cork: has joined #ruby
[11:33:06] elphe: has joined #ruby
[11:33:25] heinrich5991: has joined #ruby
[11:40:39] cpruitt: has joined #ruby
[11:46:10] p0s1x: has joined #ruby
[11:46:39] charlielor: has joined #ruby
[11:50:44] charlielor: has left #ruby: ()
[11:52:08] yxhuvud: not me. the more experience I get with grape the more I prefer pure rails
[11:58:15] jammanbo: I think I just figured it out. The formatters are defined per endpoint *I think*, so you can just `present` your object and if you've defined both a :json and a :html formatter, the appropriate one will be used.
[11:58:31] elphe: has joined #ruby
[11:59:25] jammanbo: But, yes I agree, Rails API looks increasingly like it would have been the better choice.
[12:00:36] jammanbo: I feel bad for saying that. Grape is great. Lots of love to the developers. It's just a steep curve.
[12:05:05] Paraxial: has joined #ruby
[12:09:35] za1b1tsu: has joined #ruby
[12:09:40] RougeR: has joined #ruby
[12:15:24] Cork: has joined #ruby
[12:18:10] elphe: has joined #ruby
[12:26:05] za1b1tsu: has joined #ruby
[12:30:33] cpruitt: has joined #ruby
[12:37:54] elphe: has joined #ruby
[12:45:05] cpruitt: has joined #ruby
[12:50:07] leitz: Don't feel bad; accept that some tools are better for some jobs. We all have picked up the wrong tool at times. Like Perl. :P
[12:57:38] cpruitt: has joined #ruby
[13:01:43] aufi_: has joined #ruby
[13:04:52] cpruitt: has joined #ruby
[13:05:06] cpruitt: has joined #ruby
[13:06:16] thejs: has joined #ruby
[13:07:10] RougeR: has joined #ruby
[13:09:16] bmurt: has joined #ruby
[13:10:22] vqrs: has joined #ruby
[13:13:36] AndreYuhai: has joined #ruby
[13:13:57] thy0: has joined #ruby
[13:14:36] AndreYuhai: Hello, does an instance object get garbage collected when I assign something else to the same variable which was holding the referred object before? Or how does this works? Any sources?
[13:23:41] apeiros: has joined #ruby
[13:24:22] apeiros__: has joined #ruby
[13:30:09] tbuehlmann: AndreYuhai: yup, it gets GCed if it's not referenced anymore
[13:34:47] al2o3-cr: >> arr = [1,2,3]; arr_mem = arr.object_id; arr = "foo"; ObjectSpace._id2ref arr_mem
[13:34:48] AndreYuhai: tbuehlmann: Thank you. ^^ I was wondering whether it would take so much memory because I instantiate an object a lot of times but always assigning it to the same variable.
[13:34:52] ruby[bot]: al2o3-cr: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[13:35:18] al2o3-cr: >> arr = [1,2,3]; arr_mem = arr.object_id; arr = "foo"; ObjectSpace._id2ref arr_mem
[13:35:19] ruby[bot]: al2o3-cr: # => [1, 2, 3] (https://eval.in/1057599)
[13:35:35] al2o3-cr: >> arr = [1,2,3]; arr_mem = arr.object_id; arr = "foo"; GC.start; ObjectSpace._id2ref arr_mem rescue $!
[13:35:36] ruby[bot]: al2o3-cr: # => [1, 2, 3] (https://eval.in/1057600)
[13:35:59] al2o3-cr: #=> #<RangeError: 0x00002adc74b53558 is recycled object>
[13:39:34] AndreYuhai: al2o3-cr: well looks like we don't even need to call it. I guess?
[13:40:03] al2o3-cr: not really.
[13:41:25] ua_: has joined #ruby
[13:41:57] AndreYuhai: al2o3-cr: Thank you for the example. :)
[13:42:18] al2o3-cr: AndreYuhai: np ;)
[13:46:51] elphe: has joined #ruby
[13:52:03] simmaniac: has joined #ruby
[13:56:41] sticaz: has joined #ruby
[13:56:47] RougeR: has joined #ruby
[13:56:51] ChrisBr: has joined #ruby
[13:56:57] leafyleong: has joined #ruby
[13:56:58] Sp4rKy: has joined #ruby
[13:57:07] bmurt: has joined #ruby
[13:59:17] noodle: has joined #ruby
[14:01:40] sysvalve: has joined #ruby
[14:03:12] elphe: has joined #ruby
[14:04:58] Rapture: has joined #ruby
[14:06:12] DarthGandalf: has joined #ruby
[14:08:40] amelliaa: has joined #ruby
[14:08:41] apeiros__: AndreYuhai: to elaborate a bit on tbuehlmann's response: it *can* get GCed from the moment it is not referenced anymore. but how immediate that is depends on a number of factors. that's also why finalizers are usually a bad idea.
[14:08:54] ZzZombo: has joined #ruby
[14:11:48] AndreYuhai: apeiros: What factors for example?
[14:13:15] maufart__: has joined #ruby
[14:15:12] apeiros: depends on the gc, and I'm not fully up to date with ruby's progress on its mark & sweep gc
[14:15:30] apeiros: but f.ex. it's afaik split in young and old generations
[14:15:41] havenwood: tricolor now!
[14:15:47] apeiros: so an object which existed for a long time already will take longer to be actually collected
[14:15:53] discopatrick: has joined #ruby
[14:16:00] apeiros: hah, good, I see I can just refer to havenwood for this :)
[14:16:22] apeiros: havenwood: tricolor? so they can't use a "simple" bitmap field anymore for marking?
[14:16:50] apeiros: that's the one optimization I remember well since that allowed *nix' COW fork to work in a meaningful way :)
[14:17:56] apeiros: I also seem to remember something like "arenas" being used for the implementation of the generations?
[14:18:22] apeiros: ACTION notices that he's reeeeally fuzzy by now on how ruby 2.5 or even 2.6's gc actually works :-(
[14:19:35] havenwood: apeiros: trying to find a good writeup, because i don't recall the details
[14:19:47] havenwood: this was the generational one in 2.2: https://blog.heroku.com/incremental-gc
[14:20:09] havenwood: or koichi's presentation: http://www.atdot.net/~ko1/activities/2014_rubyconf_pub.pdf
[14:20:46] AndreYuhai: havenwood: Thanks!
[14:21:02] apeiros: do you know, does yorick implement his inko in rust now?
[14:22:05] havenwood: AndreYuhai: Tenderlove gave a good talk: https://www.youtube.com/watch?v=r0UjXixkBV8
[14:22:27] apeiros: hm, 2014, I think there have been quite a bit of changes since then, no?
[14:22:48] havenwood: apeiros: yes, totally
[14:22:49] AndreYuhai: havenwood: I will watch that too. Thank you.
[14:23:03] havenwood: the mruby GC actually has great docs: https://github.com/mruby/mruby/blob/master/src/gc.c#L22-L94
[14:23:35] havenwood: i'm _fairly_ sure i'm not just thinking of mruby's GC ;-P
[14:23:37] apeiros: I hope I get around to learn rust properly in my 3 month timeout next year. if so, I'll have another go at my toy programming language.
[14:24:18] apeiros: the alternative would be to try it again in ruby, targeting WASM & bootstrapping
[14:26:49] havenwood: https://tenderlovemaking.com/2018/01/23/reducing-memory-usage-in-ruby.html
[14:28:14] havenwood: remarkably hard to find anything about modern Ruby GC
[14:28:37] havenwood: i know it's tri-color, but there's nothing written about it ¯\_(ツ)_/¯
[14:28:53] apeiros: ruby.secrets
[14:29:14] apeiros: maybe we need a 2nd edition of ruby under the microscope :)
[14:32:53] havenwood: apeiros: i said that to Shaughnessy a few weeks ago at Fog City Ruby :-)
[14:33:27] apeiros: author of the 1st edition I presume?
[14:33:54] apeiros: I think that'd be the first CS related book in a long time I'd actually buy.
[14:34:10] apeiros: back in the 1st edition I don't think I'd have learned much. but now I don't really have time to keep up :(
[14:34:54] aupadhye: has joined #ruby
[14:36:26] havenwood: took me a while, but found an actual reference to Ruby's tri-color GC!: https://youtu.be/r0UjXixkBV8?t=1342
[14:36:33] havenwood: AndreYuhai: ^
[14:36:47] apeiros: oh, youtube. can't watch at work :(
[14:36:53] apeiros: but still, thanks havenwood!
[14:38:14] AndreYuhai: havenwood: Yeap, got it! :)
[15:06:13] chouhoulis: has joined #ruby
[15:25:23] leitz: havenwood, I finally got my tests running after that minor refactor you suggested.
[15:26:04] leitz: Still have issues to fix, but mentally processing apeiros' comment about the mixin module. May need another refactor to use a Builder.
[15:26:15] bmurt: has joined #ruby
[15:26:24] leitz: I still need to understand the issue more, though.
[15:27:45] graphene: has joined #ruby
[15:35:26] graphene: has joined #ruby
[15:37:54] havenwood: leitz: nice
[15:38:23] leitz: Yeah, you say that now...wait till I start hitting you with questions. ;)
[15:44:40] TheNet: has joined #ruby
[15:45:54] apeiros: leitz: maybe just don't hit with questions? be more gentle ;-D
[15:46:15] apeiros: eh, that might come off wrong. I meant to play on the word "hit"
[15:51:42] jidar: has joined #ruby
[15:55:19] leitz: apeiros, beats "hit on", since I think havenwood and I have Significant Others that might get concerned. :)
[15:56:57] bhaak: has joined #ruby
[15:58:34] beefjoe: has joined #ruby
[16:05:31] jcarl43: has joined #ruby
[16:09:04] graphene: has joined #ruby
[16:11:56] BTRE: has joined #ruby
[16:18:08] sanscoeur: has joined #ruby
[16:18:34] graphene: has joined #ruby
[16:20:06] [Butch]: has joined #ruby
[16:23:56] dviola: has joined #ruby
[16:26:47] graphene: has joined #ruby
[16:26:54] jdawgaz: has joined #ruby
[16:30:05] Dbugger: has joined #ruby
[16:31:31] orbyt_: has joined #ruby
[16:32:06] krawchyk: has joined #ruby
[16:32:07] Puffball: has joined #ruby
[16:32:07] jcarl43: has joined #ruby
[16:33:09] sagax: has joined #ruby
[16:39:32] bmurt: has joined #ruby
[16:40:55] lxsameer: has joined #ruby
[16:42:07] jdawgaz: has joined #ruby
[16:44:54] orbyt_: has joined #ruby
[16:45:48] Inline: has joined #ruby
[16:47:14] Inline: has joined #ruby
[16:48:39] graphene: has joined #ruby
[16:50:48] lxsameer: has joined #ruby
[16:58:15] desperek: has joined #ruby
[17:00:35] lxsameer: has joined #ruby
[17:02:10] lytol_: has joined #ruby
[17:04:25] eckhardt: has joined #ruby
[17:04:54] cagomez: has joined #ruby
[17:05:31] cagomez: has joined #ruby
[17:06:04] za1b1tsu: has joined #ruby
[17:06:12] cagomez: has joined #ruby
[17:06:51] cagomez: has joined #ruby
[17:07:37] cagomez: has joined #ruby
[17:08:15] cagomez: has joined #ruby
[17:08:15] apeiros: has joined #ruby
[17:10:52] lxsameer: has joined #ruby
[17:11:26] blood: has joined #ruby
[17:14:56] blood: I can't get my ruby program to execute a command file properly : https://gist.github.com/bloodmc/965be762adf4f36072f14252e5a23c4e Any ideas?
[17:15:02] blood: Nothing is ever written to log.txt
[17:15:30] blood: when using system, the same issue occurs
[17:16:37] graphene: has joined #ruby
[17:17:38] eckhardt: has joined #ruby
[17:20:47] lxsameer: has joined #ruby
[17:23:42] NL3limin4t0r: blood: Is log.txt created? If the file is made by you try to remove it and run the script again to ensure that it at least can locate/create the file.
[17:24:51] blood: NL3limin4t0r: if i move the write line before the call to my cmd, it creates it
[17:24:59] jdawgaz: has joined #ruby
[17:25:08] blood: for some reason calling the cmd just gets stuck there and never returns
[17:26:06] resnik2: has joined #ruby
[17:26:41] resnik2: >> @n = 0; 20.times.map { Thread.start { 10000.times { @n += 1 } }}.each(&:join); puts @n
[17:26:47] ruby[bot]: resnik2: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[17:27:39] graphene: has joined #ruby
[17:27:51] resnik2: Can anyone tell me why there isn't a race condition on +=?
[17:29:00] duderonomy: has joined #ruby
[17:29:55] baweaver: gah, enter key
[17:30:00] resnik2: good answer.
[17:30:12] baweaver: How far down that rabbit hole do you want? :D
[17:30:38] resnik2: I don't understand why the timer thread doesn't kick in and suspend the currently running thread
[17:30:48] lxsameer: has joined #ruby
[17:30:48] apeiros: has joined #ruby
[17:30:50] NL3limin4t0r: blood: Does your console command return when ran in a standard cmd terminal?
[17:30:57] baweaver: Because the very succinct answer is Associative operations
[17:31:32] baweaver: 1 + 2 + 3 == 1 + (2 + 3). You could apply them in any order
[17:31:38] kwerle: has joined #ruby
[17:32:03] baweaver: It's distributable as well because of the presence of an empty value, known as identity, defined by a type and a binary operation.
[17:32:11] baweaver: Or, more simply, plus and 0
[17:32:18] resnik2: baweaver, are you replying to me?
[17:32:19] baweaver: 0 + 1 == 1 + 0 == 1
[17:32:28] baweaver: You asked why there isn't a race condition
[17:32:30] furrymcgee: has joined #ruby
[17:32:34] blood: NL3limin4t0r: good point it does not. However, the cmd is never being executed as it should be writing to another log file indicating it is running. If i execute the cmd manually, the log is updated as expected.
[17:33:06] resnik2: yes, I asked why the native thread doesn't switch to the other ruby thread in the middle of retrieaval / set operation
[17:33:11] blood: basically the cmd starts a weblogic process and eventually enters a running state
[17:33:30] resnik2: in MRI, obviously.
[17:33:36] baweaver: Technically there is a race condition, but because plus behaves in an associative manner you're not going to notice it
[17:33:44] baweaver: Try it with - or /
[17:34:13] nfk: has joined #ruby
[17:34:24] baweaver: No matter what order you add or multiply numbers in, you'll get the same result
[17:35:33] baweaver: If you want to see the order execution, use the block arg for times and output that.
[17:36:18] baweaver: @n = 0; 20.times.map { |t| p t; Thread.start { 10000.times { @n += 1 } }; p t }.each(&:join); puts @n
[17:37:01] nfk: tk's virtual event handling is driving me up the wall with the absolute lack of ruby specific documentation and none of tcl or python results i can google being of much use
[17:37:07] chouhoulis: has joined #ruby
[17:37:18] apeiros: has joined #ruby
[17:37:35] resnik2: I think I'm not getting it. Thread #1 -> GET(@n) -> 0 -> +1 <CONTEXT SWITCH> -> SET @n=1. Thread#2 -> GET(@n) -> 0 -> +1 -> SET @n=1. <CONTEXT SWITCH>
[17:37:37] elphe: has joined #ruby
[17:37:49] resnik2: already lost 1
[17:38:04] nfk: i got to the point of being able to call the handler (which is a bit ugly but whatever) but then the program gets a TypeError of all things...
[17:38:36] baweaver: ACTION wanders off to make an example
[17:39:50] resnik2: >> require 'thread'; @n = 10000; 10.times.map { Thread.start { 1000.times { @n -= 1 } }}.each(&:join); puts @n
[17:39:51] ruby[bot]: resnik2: # => (https://eval.in/1057690)
[17:40:05] NL3limin4t0r: blood: Hmm, that's strange. Are you sure you point to the right direction? You could test if using backticks instead of using Open3 helps.
[17:40:27] NL3limin4t0r: eg. result = `your cmd command here`
[17:40:48] lxsameer: has joined #ruby
[17:40:52] blood: I just tried executing 'dir' and same result
[17:40:56] blood: ok let me try that
[17:41:10] NL3limin4t0r: You might need to escape backslashes
[17:41:58] apeiros: has joined #ruby
[17:43:28] baweaver: resnik2: https://repl.it/@baweaver/YoungHeartyTrapezoids
[17:44:28] furrymcgee: n a ruby script there is a error in the line: public :eof?
[17:44:42] resnik2: I don't care about execution order, all I care why is total correct
[17:44:57] baweaver: furrymcgee: you'll have to share a bit more than that.
[17:45:00] furrymcgee: ./makeref:194:in `public': undefined method `eof?' for class `TokenStream'
[17:45:20] baweaver: TokenStream doesn't have an eof? method
[17:45:58] blood: N3limin4t0r: same issue happens. Any debugging I can turn on to see what is happening?
[17:46:04] furrymcgee: the next line is def eof?
[17:46:38] apeiros: furrymcgee: the method has to be defined
[17:46:43] baweaver: gotta run, train is getting to the station
[17:46:57] apeiros: you can't mark a method which isn't yet defined as public/protected/private
[17:47:07] blood: I'm using ruby 2.4.4p296 (2018-03-28 revision 63013) [x64-mingw32]
[17:47:10] blood: if that helps
[17:47:22] NL3limin4t0r: blood: There is the "byebug" gem.
[17:47:39] apeiros: furrymcgee: also, unless you inherit from a class where eof? is private, there's no point really in doing `public :your_method`
[17:47:58] chouhoulis: has joined #ruby
[17:48:02] NL3limin4t0r: Once installed you can place `byebug` in your file (after require 'byebug')
[17:48:13] NL3limin4t0r: Execution will stop on that line
[17:48:30] blood: very nice, let me try that
[17:49:35] blood: hrmm, doesn't work for mingw32, it fails during install
[17:50:51] resnik2: >> @n = 50000; 50.times.map { Thread.start { 1000.times { @n -= 1 } }}.each(&:join); puts @n
[17:50:53] ruby[bot]: resnik2: # => (https://eval.in/1057702)
[17:50:53] lxsameer: has joined #ruby
[17:51:56] apeiros: resnik2: no threads in ruboto (eval.in restricts that)
[17:51:58] resnik2: still not getting what's stopping currently running thread from being "suspended" in the middle of GET/SET -= op
[17:53:00] NL3limin4t0r: blood: Hmm, can't help you with the install. I'm currenty in my Ubuntu environment.
[17:53:29] apeiros: resnik2: re your original question: there is a race condition in that code.
[17:53:42] apeiros: resnik2: it's just that race conditions don't always trigger
[17:54:52] SeepingN: has joined #ruby
[17:55:00] NL3limin4t0r: blood: https://stackoverflow.com/questions/3955688/how-do-i-debug-ruby-scripts might be worth a look. I guess the main question now is why aren't shell commands not executing. It might be due to the fact that you are running ruby on windows tbh.
[17:55:15] jdawgaz: has joined #ruby
[17:55:52] resnik2: loop { @n = 50000; 50.times.map { Thread.start { 1000.times { @n -= 1 } }}.each(&:join); puts :FINALLY unless 0 == @n }
[17:55:54] NL3limin4t0r: I'm guessing the command is send to a mingw32 shell instead.
[17:56:01] resnik2: it seems the answer is NEVER on mri.
[17:56:08] vutral|kali: has joined #ruby
[17:59:23] nfk: is it just me or virtual event in ruby/tk handling is not working as it's supposed to?
[17:59:27] apeiros: it's quite possible that newer rubies don't schedule other threads between +=/-= in certain cases (e.g. numeric receiver), in that case you'd indeed not have a race condition.
[18:00:03] nfk: *virtual event handling
[18:00:47] lxsameer: has joined #ruby
[18:01:10] dellavg_: has joined #ruby
[18:03:21] apeiros: but relying on that would be relying on an implementation detail. the code is not correct.
[18:10:43] NL3limin4t0r: I once read an article somewhere about this exact issue, comparing MRI and JRuby. However I currently can't seem to find it.
[18:10:51] lxsameer: has joined #ruby
[18:11:36] NL3limin4t0r: Point is that the code breaks when running it in JRuby if you coun't on it being thread safe (which it obviously isn't).
[18:13:34] resnik2: apeiros, yeah, something's strange going on there, but it also works fine on 1.9, so I guess something's tricky with ruby scheduler. The whole thing popped up when I was conducting Mutex#synchronize benchmarks.
[18:14:02] VeryBewitching: has joined #ruby
[18:16:22] resnik2: And those were needed because somehow I've got a feeling hiredis is doing bad job of multithreading in mri
[18:17:22] VeryBewitching: Hey folks, I'm trying to find a way to undefine a method in a module, not really getting anywhere; in a test environment I'd like the Service method redefined, how would I go about removing the original? https://gist.github.com/bewitchingme/3e7a75e05dc5a57641908c47567572c7
[18:17:44] tdy: has joined #ruby
[18:17:55] VeryBewitching: Oddly, simply redefining it has no effect to the test, it simply uses the original definition
[18:18:14] cd: has joined #ruby
[18:18:30] blood: NL3limin4t0r: so i got it installed but it doesn't seem to be doing anything
[18:18:41] VeryBewitching: I've tried undef_method and remove_method in the module, to no effect.
[18:19:32] blood: ok im able to use `byebug rubyfile.rb`
[18:19:38] blood: let me dig further
[18:20:52] NL3limin4t0r: resnik2: This might be intresting https://dev.to/enether/rubys-gil-in-a-nutshell
[18:20:58] lxsameer: has joined #ruby
[18:22:26] snuz: has joined #ruby
[18:22:33] NL3limin4t0r: blood: You should be able to call `byebug` inside your script to set a breakpoint you can build ruby logic around it if you want `byebug if false` will never break your code.
[18:23:37] NL3limin4t0r: The most important commants are `c` to continue until the next break point, `n` to execute the next statement and `s` to step into a method of the current line.
[18:24:58] NL3limin4t0r: and obviously `exit` and `help`
[18:25:07] blood: so running `c` in byebug will go to next `byebug` command i have in my rb file?
[18:25:20] blood: byebug creates a breakpoint ?
[18:25:40] blood: ok when i use `c` it just runs for a few more seconds then exits
[18:25:45] blood: yet i have multiple byebug's
[18:25:58] blood: shall i post the entire rb file?
[18:26:41] NL3limin4t0r: sure, create a gist or use https://dpaste.de/
[18:27:29] blood: https://gist.github.com/bloodmc/35f6b008448c8db85142dbe2a84d723d
[18:27:41] blood: i removed the byebug's
[18:28:37] headius: NL3limin4t0r: you can't rely on that code in MRI either because it doesn't treat the -= as atomic either
[18:29:10] resnik2: <VeryBewitching> https://repl.it/repls/FrivolousComfortableCharactercode
[18:29:41] VeryBewitching: resnik2: Ooh, imma try that, thanks :D
[18:30:36] eckhardt: has joined #ruby
[18:30:43] VeryBewitching: resnik2: Nope, still complains it can't find the method.
[18:30:57] lxsameer: has joined #ruby
[18:31:10] VeryBewitching: It's not an instance method of the module, it's a method on the module itself, I think that trips it up a bit
[18:31:24] resnik2: you asked to remove the method, that's what I did. You want to define a method?
[18:31:26] VeryBewitching: def self.Service; end
[18:31:40] VeryBewitching: I'm trying to redefine that method for a test.
[18:31:50] VeryBewitching: So I'm not making calls to the target webservice, but to a mock
[18:32:14] VeryBewitching: Just redefining it has no effect, it continues to use the original in the app.
[18:32:31] VeryBewitching: So I was trying to remove the original and define it, not having much luck.
[18:32:48] resnik2: self.define_singleton_method :Service, { puts :see }
[18:33:21] xfbs: has joined #ruby
[18:34:56] resnik2: VeryBewitching, I'd say you've got everything right, look elsewhere.
[18:35:15] clemens3_: has joined #ruby
[18:35:30] VeryBewitching: It might be the order the files are being auto loaded; I'd considered that too
[18:36:30] leafyleong: has joined #ruby
[18:36:44] snuz: has joined #ruby
[18:36:46] VeryBewitching: resnik2: Thanks for your time :)
[18:40:34] xfbs: has joined #ruby
[18:40:52] lxsameer: has joined #ruby
[18:43:44] jdawgaz: has joined #ruby
[18:48:53] dviola: has joined #ruby
[18:51:08] lxsameer: has joined #ruby
[18:51:50] nfk: i would very much like to hear from someone who knows ruby/tk on how to get virtual event handling working
[18:59:21] Fusl: has joined #ruby
[19:00:01] xfbs: has joined #ruby
[19:00:54] lxsameer: has joined #ruby
[19:06:58] agent_white: has joined #ruby
[19:10:03] leitz: Okay havenwood, I told you I'd be back with questions. https://github.com/makhidkarun/ftl_chargen/blob/builder_01/lib/ftl_chargen/builder.rb#L20
[19:10:32] leitz: The error is: builder.rb:20:in `generate_upp': undefined method `[]=' for #<FTLChargen::Character:0x0000563c9b8a2c48> (NoMethodError)
[19:10:52] leitz: But Character has an attr_accessor for upp.
[19:11:04] lxsameer: has joined #ruby
[19:11:18] leitz: What am I missing?
[19:15:59] thejs: has joined #ruby
[19:18:04] za1b1tsu: has joined #ruby
[19:20:59] lxsameer: has joined #ruby
[19:24:37] sameerynho: has joined #ruby
[19:25:41] xfbs: has joined #ruby
[19:30:55] lxsameer: has joined #ruby
[19:32:25] jdawgaz: has joined #ruby
[19:32:30] eam: has joined #ruby
[19:34:16] Nicmavr: has joined #ruby
[19:38:23] leitz: Okay...figured that one out.
[19:49:53] xfbs: has joined #ruby
[19:54:56] cek: has joined #ruby
[19:55:16] cek: has left #ruby: ()
[19:55:58] graphene: has joined #ruby
[20:10:09] nowhere_man: has joined #ruby
[20:11:49] xfbs: has joined #ruby
[20:13:14] llua: has joined #ruby
[20:19:52] jdawgaz: has joined #ruby
[20:26:31] xfbs: has joined #ruby
[20:39:52] xfbs: has joined #ruby
[20:55:43] c0ncealed2: has joined #ruby
[21:01:08] brandoncc: has joined #ruby
[21:04:04] xfbs: has joined #ruby
[21:09:15] cagomez: has joined #ruby
[21:09:50] cagomez: has joined #ruby
[21:10:30] cagomez: has joined #ruby
[21:11:15] cagomez: has joined #ruby
[21:11:55] cagomez: has joined #ruby
[21:12:34] cagomez: has joined #ruby
[21:16:25] RougeR: has joined #ruby
[21:16:28] yohji: has joined #ruby
[21:17:24] zenspider: leitz: what did you figure out?
[21:18:37] cats: has joined #ruby
[21:19:40] xfbs: has joined #ruby
[21:23:40] baweaver: havenwood: do you remember where that Ruby list comprehension gist was?
[21:26:09] havenwood: baweaver: this one or was it another?: https://gist.github.com/postmodern/605891
[21:28:41] graphene: has joined #ruby
[21:31:47] baweaver: We should comment it up later for kicks
[21:31:56] baweaver: https://gist.github.com/andkerosine/3356675
[21:31:59] baweaver: There it was!
[21:32:25] zenspider: for non-predicate version, this seems huge
[21:32:28] zenspider: >> a = [(1..5),(1..4),(1..3)].map(&:to_a); a.first.product(*a[1..-1])
[21:32:29] ruby[bot]: zenspider: # => [[1, 1, 1], [1, 1, 2], [1, 1, 3], [1, 2, 1], [1, 2, 2], [1, 2, 3], [1, 3, 1], [1, 3, 2], [1, 3, 3], ...check link for more (https://eval.in/1057740)
[21:35:33] lxsameer: has joined #ruby
[21:40:55] ivanskie: has joined #ruby
[21:48:17] akem: has joined #ruby
[22:01:12] thy0: has joined #ruby
[22:08:24] leitz: zenspider, me being confused on setting an object's attribute.
[22:08:46] leitz: Sometimes I'm a little slow...
[22:13:04] leitz: Well, storm is finally almost here. Will be shutting down in a bit. hopefully we don't wash away.
[22:18:44] Giruvagen: has joined #ruby
[22:30:03] cpruitt: has joined #ruby
[22:30:29] Azure: has joined #ruby
[22:30:38] xfbs: has joined #ruby
[22:32:19] nowhere_man: has joined #ruby
[22:32:58] cats: has joined #ruby
[22:33:00] thy0: has joined #ruby
[22:44:24] jdawgaz: has joined #ruby
[23:33:40] postmodern: has joined #ruby
[23:36:15] lxsameer: has joined #ruby
[23:37:53] jdawgaz: has joined #ruby