« Back to channel list

#ruby - 17 September 2018

« Back 1 day Forward 1 day »
[00:05:07] patr0clus: has joined #ruby
[00:14:51] armyriad: has joined #ruby
[00:34:05] bmurt: has joined #ruby
[00:49:59] cschneid_: has joined #ruby
[00:53:51] Nicmavr: has joined #ruby
[00:56:17] duderonomy: has joined #ruby
[01:03:58] bmurt: has joined #ruby
[01:04:42] lunarkittychan: has joined #ruby
[01:10:32] xfbs: has joined #ruby
[01:14:05] samort7: has joined #ruby
[01:19:49] gix: has joined #ruby
[01:22:34] s2013: has joined #ruby
[01:27:03] gix: has joined #ruby
[01:30:24] apparition: has joined #ruby
[01:39:17] orbyt_: has joined #ruby
[01:43:42] s2013: has joined #ruby
[01:45:04] esrse: has joined #ruby
[01:45:43] vasilakisFiL: has joined #ruby
[01:46:01] vasilakisFiL: I am a bit confused: is there an as_json method in Ruby or is it only Rails ?
[02:01:51] tdy: has joined #ruby
[02:04:24] vasilakisFiL: I guess it's railsy
[02:17:21] regedit: has joined #ruby
[02:26:56] darkhanb: has joined #ruby
[02:33:01] ZzZombo: has joined #ruby
[02:38:44] cschneid_: has joined #ruby
[02:46:21] ivanskie: has joined #ruby
[03:10:45] braincrash: has joined #ruby
[03:10:48] tdy: has joined #ruby
[03:14:49] tristanp: has joined #ruby
[03:18:22] darkhanb: has joined #ruby
[03:38:57] ivanskie: has joined #ruby
[03:52:04] cschneid_: has joined #ruby
[04:08:46] darkhanb: has joined #ruby
[04:23:05] ivanskie: has joined #ruby
[04:35:37] cschneid_: has joined #ruby
[04:39:50] lytol_: has joined #ruby
[04:46:33] lunarkittychan: has joined #ruby
[04:53:33] ZzZombo: `Gem::LoadError: can't activate pg (~> 0.11), already activated pg-1.1.3-x86-mingw32. Make sure all dependencies are added to Gemfile.`
[04:53:42] ZzZombo: What to do to get rid of this error?
[04:54:11] BTRE: has joined #ruby
[04:57:05] cschneid_: has joined #ruby
[04:58:23] ZzZombo: I do have `gem 'pg', '~> 1.1.3'` in my `Gemfile`, and no single trace of `~> 0.11` even if either `Gemfile` or `Gemfile.lock`.
[05:06:48] kapil___: has joined #ruby
[05:10:26] cschneid_: has joined #ruby
[05:14:44] reber: has joined #ruby
[05:38:30] T3RM1N41: has left #ruby: ()
[05:41:08] snickers: has joined #ruby
[05:43:26] Radar: ZzZombo: What exactly are you running to get that error?
[05:43:35] Radar: ZzZombo: does that command start with "bundle exec" or no?
[05:43:38] ZzZombo: a rake command
[05:44:44] tdy: has joined #ruby
[05:45:02] tuor: has joined #ruby
[05:46:11] ZzZombo: Radar: looked it up, it's `rake populate:users`.
[05:46:29] Radar: ZzZombo: try: `bundle exec rake populate:users`. It's probably not running within a Bundler context, which is why it is ignoring your Gemfile.
[05:49:25] ZzZombo: Radar: nothing changed.
[05:49:35] cschneid_: has joined #ruby
[06:03:14] s2013: has joined #ruby
[06:13:46] aupadhye: has joined #ruby
[06:15:09] Xiti`: has joined #ruby
[06:20:06] DK2: has joined #ruby
[06:23:25] darkhanb: has joined #ruby
[06:28:43] cschneid_: has joined #ruby
[06:28:55] aufi: has joined #ruby
[06:36:30] MoritaShinobu: has joined #ruby
[06:41:19] im0nde: has joined #ruby
[06:41:48] cschneid_: has joined #ruby
[06:42:42] Mike11: has joined #ruby
[06:55:18] MoritaShinobu: has joined #ruby
[06:59:00] cschneid_: has joined #ruby
[06:59:14] madhatter: has joined #ruby
[07:08:20] lomex: has joined #ruby
[07:10:18] sysvalve: has joined #ruby
[07:16:04] cschneid_: has joined #ruby
[07:24:36] aufi: has joined #ruby
[07:24:39] s2013: has joined #ruby
[07:25:16] nowhere_man: has joined #ruby
[07:31:01] clemens3: has joined #ruby
[07:38:05] cschneid_: has joined #ruby
[07:43:57] roshanavand: has joined #ruby
[07:52:47] vondruch: has joined #ruby
[07:53:27] Mortomes|Work: has joined #ruby
[07:55:25] cschneid_: has joined #ruby
[08:05:02] TheBloke-: has joined #ruby
[08:14:23] alem0lars: has joined #ruby
[08:21:29] Emmanuel_Chanel: has joined #ruby
[08:21:41] RougeR: has joined #ruby
[08:26:27] cschneid_: has joined #ruby
[08:28:15] z4phod: has joined #ruby
[08:32:27] lxsameer: has joined #ruby
[08:34:10] SuperL4g_: has joined #ruby
[08:37:30] moei: has joined #ruby
[08:54:52] mikecmpbll: has joined #ruby
[08:57:17] SuperLag: has joined #ruby
[08:57:33] Emmanuel_Chanel: has joined #ruby
[09:01:14] schneider1: has joined #ruby
[09:05:07] Dark_Arc: has joined #ruby
[09:08:11] xfbs: has joined #ruby
[09:08:59] nowhere_man: has joined #ruby
[09:09:20] cschneid_: has joined #ruby
[09:11:45] chichou: has joined #ruby
[09:16:08] Beams: has joined #ruby
[09:18:04] cschneid_: has joined #ruby
[09:23:46] dalpo: has joined #ruby
[09:26:52] cschneid_: has joined #ruby
[09:28:56] yohji: has joined #ruby
[09:31:51] cschneid_: has joined #ruby
[09:33:18] TheBloke: has joined #ruby
[09:43:29] TheBloke: has joined #ruby
[09:49:14] cschneid_: has joined #ruby
[10:06:10] ua: has joined #ruby
[10:08:47] jottr: has joined #ruby
[10:13:49] tristanp: has joined #ruby
[10:14:01] jottr: has joined #ruby
[10:22:05] emers3n: has joined #ruby
[10:29:30] emers3n: I am using gsub to find and replace a string "{{ example-function }}". I want to allow fuzzyness between the brackets and 'example-function', so strings like "{{ example-function | extra-function-options }}" still match... Is this possibly w/o additional gem?
[10:29:33] apeiros: has joined #ruby
[10:37:37] mikecmpb_: has joined #ruby
[10:41:36] cschneid_: has joined #ruby
[10:49:35] apparition: has joined #ruby
[10:59:08] cschneid_: has joined #ruby
[11:02:58] donofrio: has joined #ruby
[11:07:23] rgr: has joined #ruby
[11:12:41] apeiros_: has joined #ruby
[11:18:07] mnemon: emers3n: yes, you can use regexp with gsub
[11:20:50] cschneid_: has joined #ruby
[11:23:48] ZzZombo: has joined #ruby
[11:27:12] Mortomes|Work_: has joined #ruby
[11:29:01] mikecmpbll: has joined #ruby
[11:33:56] cschneid_: has joined #ruby
[11:34:01] Nicmavr: has joined #ruby
[11:35:45] ldnunes: has joined #ruby
[11:37:21] venmx: has joined #ruby
[11:39:25] venmx: hi, has anyone ever used a secrets app called arcanus? i'm getting error when trying to install on alpine docker image... says ERROR: Failed to build gem native extension. any ideas?
[11:47:23] aupadhye: has joined #ruby
[12:01:07] pyrmont: emers3n: http://rubular.com is a good site for practising different regex combinations to see which works for your situation.
[12:03:00] Xeago_: has joined #ruby
[12:03:56] FirstLoveLife: has joined #ruby
[12:14:23] roshanavand: has joined #ruby
[12:14:32] tristanp: has joined #ruby
[12:14:54] sheepman: has joined #ruby
[12:14:58] sheepman: hi all, whats the simplest way of finding if an Array contains both true and false booleans?
[12:16:01] emers3n: thanks pyrmont, mnemon
[12:16:20] AJA4350: has joined #ruby
[12:19:04] pyrmont: sheepman: Simplest is probably #include?
[12:19:51] sheepman: but for two elements?
[12:20:39] DarthGandalf: has joined #ruby
[12:22:43] InfinityFye: has joined #ruby
[12:27:26] pyrmont: Just run it twice?
[12:28:39] pyrmont: You can do more complicated things: do #select with a block and check the length of the result but that seems more obtuse to me.
[12:35:01] cschneid_: has joined #ruby
[12:36:28] Xiti: has joined #ruby
[12:39:04] im0nde: has joined #ruby
[12:43:24] sheepman: ok thanks pyrmont
[12:45:38] RougeR: yeah sheepman literally foo.include(true) would work
[12:46:47] RougeR: sorry oo.include(true && false)
[12:47:57] apeiros_: RougeR: that won't work.
[12:48:25] RougeR: Apocalypse: why not?
[12:48:27] pyrmont: I don't think that'll work the way you expect. true && false will resolve to false and you'll just be checking for false.
[12:48:37] RougeR: i just tried it in pry
[12:48:42] RougeR: leme double check
[12:48:46] apeiros: a) it's include?, not include, b) oo.include(true && false) will evaluate `true && false` first, which becomes `false` and hence is just oo.include?(false)
[12:49:06] thy0: has joined #ruby
[12:49:40] apeiros: possible solutions:
[12:49:51] apeiros: a) ary.include?(true) && ary.include?(false)
[12:50:07] apeiros: b) [true, false].all? { |value| ary.include?(value) }
[12:50:17] apeiros: c) ([true, false] - ary).empty?
[12:51:27] RougeR: 3rd one seems best
[12:51:43] RougeR: still 2 loops isnt it though
[12:52:13] Mortomes|Train: has joined #ruby
[12:53:13] apeiros: no, c is one loop
[12:53:36] apeiros: but for small left sides, it might easily be slower than a)
[12:54:11] RougeR: could also use sets id think
[12:54:24] apeiros: Array#- is a set operation.
[12:54:42] apeiros: and unless you start out with Set instances, it's faster than converting to Set + performing the operation
[12:55:43] IanMalcolm: has joined #ruby
[13:03:22] jcalla: has joined #ruby
[13:07:39] InfinityFye: has joined #ruby
[13:10:16] xfbs: has joined #ruby
[13:15:03] toiletpaper5: has joined #ruby
[13:20:09] FirstLoveLife: has joined #ruby
[13:24:25] jottr: has joined #ruby
[13:25:48] sauvin: has joined #ruby
[13:29:45] jottr: has joined #ruby
[13:29:53] xfbs: has joined #ruby
[13:31:02] bmurt: has joined #ruby
[13:31:29] za1b1tsu: has joined #ruby
[13:37:51] kapil___: has joined #ruby
[13:38:06] fluxAeon: has joined #ruby
[13:38:56] sauvin: has joined #ruby
[13:45:26] RougeR: has joined #ruby
[13:55:13] arup_r: has joined #ruby
[13:55:40] vondruch: has joined #ruby
[13:59:24] Rapture: has joined #ruby
[14:00:01] gnufied: has joined #ruby
[14:03:18] alem0lars: has joined #ruby
[14:06:39] Inline: has joined #ruby
[14:07:59] Inline: has joined #ruby
[14:13:44] snickers: has joined #ruby
[14:24:22] IanMalcolm: has joined #ruby
[14:30:31] jottr: has joined #ruby
[14:36:43] m27frogy: has joined #ruby
[14:38:01] xfbs: has joined #ruby
[14:41:07] cschneid_: has joined #ruby
[14:44:20] nfk: has joined #ruby
[14:47:50] nfk: hello, sorry for my google skills failing me on this silly question but how do i get and process output of a block? i'm iterating over a Dir.glob with a block and the final value of each iteration is already what I want but I can't figure out how to collect them in an array or even just a string without using something ugly like passing a variable into the block, which I could to but i'm certain there's a more beautiful ruby way to do it
[14:53:20] apeiros: nfk: your question is a bit ambiguous, I think you want `mapped = Dir.glob(glob_expr).map { |path| …process(path)… }`
[14:53:32] nfk: apeiros, yeah, i literally just wrote that into my code
[14:53:35] nfk: testing it now
[14:54:16] nfk: i feel a bit silly now but it proves that it's all about asking the right question. btw just out of curiosity can i collect the final value of each iteration in ruby?
[14:56:11] apeiros: map does that. if you truly mean "of each iteration"
[14:56:35] nfk: yeah, i just printed what i wanted: ["usr", "boot", "bin", "dev", "etc", "home", "lib", "lib64", "media", "mnt", "newroot", "opt", "proc", "root", "run", "sbin", "srv", "sys", "tmp", "var", "fio"]
[14:56:43] nfk: needs more work, naturally but at least i'm getting there
[14:56:59] nfk: now.. if only ruby had a decent gui and i didn't have to write on in capistrano :D
[14:59:00] snickers: has joined #ruby
[15:00:29] c0ncealed2: has joined #ruby
[15:00:31] nfk: apeiros, btw, is it better on humane grounds to assign a Dir.glob array to a variable and then map { ... }.sort! that or to just go Dir.glob ... .sort in one swell swoop?
[15:01:32] apeiros: depends. assigning to local variables gives you an opportunity to name intermediate results, making it easier to read the code
[15:01:37] nfk: i'm inclined towards the later but i can't recall anyone ever having done that so i'm a bit worried about the sanity of anyone who might read my code
[15:01:44] apeiros: on another note: *never* use bang methods from core when you want the return value.
[15:01:49] aufi: has joined #ruby
[15:02:18] apeiros: many of them will return nil if nothing changed
[15:02:19] nfk: apeiros, come again on that, please? I'm not sure i groked that
[15:02:55] apeiros: so: `Dir.glob(x).map { … }.select { … }.sort`, not `Dir.glob(x).map! { … }.select { … }.sort!`
[15:03:14] nfk: huh, would that be like [1, 2, 3].map! {|n| n*n } => [nil, 4, 9]?
[15:03:40] apeiros: >> "HI".upcase!
[15:03:41] ruby[bot]: apeiros: # => nil (https://eval.in/1058379)
[15:03:55] nfk: that boggles my mind
[15:05:12] nfk: why would 1 be returned when 1 and the return value of 1*1 should be the same object just like "HI" and "HI".upcase! ?
[15:05:48] IanMalcolm: has joined #ruby
[15:06:51] apeiros: no, if map! worked like upcase!, the whole return value would be nil, not just a single element.
[15:07:02] apeiros: but map! actually is one of the bang methods which will return self.
[15:07:44] bmurt: has joined #ruby
[15:08:11] nfk: so map! is safe but sort!, upcase! and most others are not?
[15:09:07] duderonomy: has joined #ruby
[15:09:15] apeiros: I don't bother to remember which ones are and which ones aren't. I find it easier to just use the rule "return value -> no bang, in-place -> bang"
[15:09:36] apeiros: (though, bang actually only means "be careful", but it's almost always used for in-place variants)
[15:09:54] nfk: yeah, thanks both for your initial answer and this explanation. i have a weird feeling that i might have hit that landmine before but never figured out what was going on and just not used map altogether
[15:10:02] nfk: oh wait, not map but..
[15:11:02] nfk: hmm.. i can remember the Rails project which gave me the most headaches but can't recall which method i got to work around as it was just giving me missing values
[15:14:49] Mike11: has joined #ruby
[15:15:46] cagomez: has joined #ruby
[15:17:13] cagomez_: has joined #ruby
[15:17:15] phaul: has joined #ruby
[15:19:43] phaul: hi, can someone point me some freely available material on Ruby lexical scopes? I've read some contradictory info and now I'm more confused than before I started my research ..
[15:19:53] cagomez__: has joined #ruby
[15:21:21] conta: has joined #ruby
[15:21:58] cadillac_: has joined #ruby
[15:23:57] phaul: this guy is talking about 3 different scopes: http://rubyblog.pro/2017/02/scope-gates-and-flat-scope-ruby which is what I also read in the Metaprogramming Ruby book. but then here https://stackoverflow.com/questions/23209249/how-does-scope-work-in-ruby/23209598#23209598 the consesnus seems to be that we have 5 scopes.
[15:24:28] phaul: I must be misunderstanding something.. What is it?
[15:31:29] IanMalcolm: has joined #ruby
[15:34:46] beowuff: has joined #ruby
[15:34:56] havenwood: phaul: I don't understand the premise of the question. Places like top level actually have a different context for setting and getting methods and method lookup than they do for defining of methods and constants. Do you count top level as then not a scope, but using that of an Object instance and also the Object class?
[15:35:11] havenwood: phaul: Scope of what?
[15:35:52] havenwood: phaul: There are lexically scoped things, like refinements. I don't think any of the answers are right. :P
[15:36:53] phaul: I would like to have a thorough understanding of this. What should I read?
[15:37:00] nfk: i think the first question here should be what is a scope
[15:37:42] nfk: e.g. would a piece of code such as this: foo = "bar" introduce a variable that does not exist beyond certain bounds be considered a scope?
[15:38:04] nfk: let me regrammarise that
[15:38:15] havenwood: so we should limit the scope of the question to what is a scope?
[15:38:21] havenwood: how many scopes does this question have?
[15:38:35] nfk: e.g. would a piece of code such as this: foo = "bar" introducing a variable that does not exist beyond certain bounds be considered to define those bounds as a scope?
[15:39:06] nfk: havenwood, no, that's the first question because i suspect that ruby has at least two answers to his original question depending on how one defines a scope
[15:39:27] phaul: nfk: what are your scope definitions?
[15:39:29] nfk: that having been said, i personally do not care about such things so it's just a hunch i have after years of rubying sometimes
[15:40:20] snickers: has joined #ruby
[15:40:29] nfk: phaul, i'm just a noob, sorry. but my first one would be what i just asked. the second one is probably along the lines of either language design intent and lexical/syntactical distinctions but i do not know how to define it more clearly
[15:42:05] phaul: Ok let's say we take the first one as the definition of a 'scope'. How many different things qualify as a scope then?
[15:42:24] havenwood: phaul: scope of what?
[15:42:48] havenwood: phaul: context for setting and getting methods and method lookup?
[15:42:59] nfk: phaul, but if you want an answer from a noob, then i'd say that stackoverflow guy with 5 is closer to a practical definition of a scope even if the linguistically correct answer is a smaller number. Also I suspect the "expert" intentionally avoided the top level (script?) scope as it's not an intentional scope but a requirement to make the language work (i think)
[15:43:05] havenwood: phaul: context for defining of methods and constants?
[15:44:02] phaul: havenwood: let's say scope of nfk's first definition
[15:44:22] nfk: havenwood, how about instead of answering a question with a question you gave us your honest opinion to the question of "how many scopes does ruby have?"
[15:44:33] havenwood: phaul: so getting local variables?
[15:45:10] havenwood: nfk: That's a nonsensical question. I already answered in my first comment. I do not accept the premise of there being a number of "scopes" that Ruby has.
[15:45:27] havenwood: nfk: If you want a number, I say 42.
[15:47:09] havenwood: nfk: It's like saying how many wins does Ruby have. I just don't get it.
[15:47:48] havenwood: phaul: I guess there's two, the scope where you can get that variable and the scope where you can't. :P
[15:48:10] phaul: havenwood: not helpful.
[15:48:29] nfk: havenwood, look, i might be a ruby noob but i do have a degree in software engineering. a scope is a perfectly valid if a bit practically-conceptual term that denotes contexts within programming language where defining or redefining things do not clobber things of the same name and type in another scope
[15:49:16] havenwood: nfk: So many things have scopes, right. The scope for variable lookup is not the same for constant assignment. It's more complex than simple counting of a single plane of a thing.
[15:49:39] havenwood: nfk: It's like saying what is the count of our body parts. Then getting mad at a physician who says there's not a straightforward count.
[15:49:49] havenwood: nfk: Is an arm one part? 50?
[15:50:23] havenwood: nfk: I'm not debating there ARE body parts. I'm objecting to meaning of counting them.
[15:50:47] havenwood: nfk: There are scopes in Ruby, and it's interesting to talk about.
[15:51:46] havenwood: I have no clue how to meaningfully count them.
[15:52:28] nfk: havenwood, which is why after years of rubying i still can't answer this basic question ;) i kinda get what you're saying and that's also exactly what i feel about the definition of bodyparts but i still prefer to have a loose yet practical definition over saying: "Reality is too dificult to describe exactly so let's either give up or use some totally abstract yet mathematically valid notation"
[15:53:01] havenwood: nfk: I'd love to talk about how the arm works. I just don't know how to count its parts meaningfully.
[15:53:49] havenwood: For example, here's an article banisterfiend wrote about Ruby's interesting scope at top level: https://banisterfiend.wordpress.com/tag/top-level/
[15:54:15] havenwood: Is it the scope of an Object? A Class? Both!
[15:54:42] justinweiss: has joined #ruby
[15:55:09] nfk: havenwood, i know, just like a vegetable is completely arbitrary definition for roots and fruits and whatnot, so does that mean we should forget about the the word "vegetable" or answer: "how many fingers does a human arm have?" with: "there are no arms because they're too dificult to define"
[15:55:55] havenwood: I think zooming in gives more interesting detail to debate. Like, "how many scopes are there in Ruby top level?"
[15:56:03] NL3limin4t0r: has joined #ruby
[15:56:16] havenwood: Counting a thing that itself has many scopes as one scope is suspect.
[15:56:35] nfk: wasn't ruby supposed to not surprise people familiar with it?
[15:57:17] havenwood: nfk: Nope. It's supposed to be the principle of least surprise to *Matz*.
[15:57:42] phaul: nfk: I'm not even surprised any more :)
[15:58:15] havenwood: nfk: What Matz has to say about it is interesting. He was surprised others liked what he liked so much.
[15:58:53] havenwood: nfk: I guess the closer you think to Matz, the less surprise it will be.
[15:59:17] nfk: except i want to think like myself
[15:59:44] darkhanb: has joined #ruby
[15:59:47] havenwood: I don't think Ruby is a simple language. That might be why few universities seem to teach with it.
[16:00:17] ivanskie: has joined #ruby
[16:00:18] phaul: havenwood: is there a meaningful count on how many different scope definitions can be? And then for each we could argue how many Ruby has... Where of course the number itself is not interesting, but what those scopes are is.
[16:00:19] nfk: it has a lot more to do with it not having a connection to the academia
[16:00:26] havenwood: It may be easy for an experienced C programmer to adopt, but it's not simple.
[16:00:28] havenwood: nfk: Maybe so
[16:01:57] havenwood: phaul: It's kinda a separate question for constants, variables, methods, etc.
[16:02:15] havenwood: phaul: Each is intersting.
[16:02:17] havenwood: phaul: Just constant lookup and scope is a whole thing to dig into.
[16:02:32] havenwood: phaul: Or just method lookup and scope is too.
[16:03:05] nfk: phaul, so in short, there's >=5 scopes in ruby; whether to go down the rabbithole or do something else is up to you
[16:03:15] havenwood: phaul: Methods for example have different scopes for definition than they do for getting and setting. It's a rabbit hole.
[16:03:24] nfk: also "expert" is anyone who has written a book, write one yourself
[16:04:16] havenwood: Ruby Under a Microscope is a good book on the subject.
[16:04:18] phaul: havenwood: what's setting and getting?
[16:04:27] havenwood: http://patshaughnessy.net/ruby-under-a-microscope
[16:04:52] phaul: cool. I will read that.
[16:05:02] nfk: ACTION wonders if that might have been a shameless plug
[16:06:11] phaul: altough I still would like to know what's the getting and setting of methods?
[16:06:29] ams__: has joined #ruby
[16:07:51] havenwood: phaul: that was just my mistake. I meant getting and setting of variables. the lookup of methods.
[16:07:58] havenwood: phaul: sorry, i'm pre-coffee
[16:08:15] phaul: np., I was just confused that's all
[16:08:24] havenwood: nfk: Nope! I do know Pat from Ruby meetups and confs but I didn't write the book or edit it or anything.
[16:08:26] NL3limin4t0r: athough you can get and set a method too
[16:08:41] NL3limin4t0r: `some_object.method(:some_method)` would be the getter
[16:09:30] havenwood: phaul: Binding is really interesting in Ruby. Are you familiar with that?
[16:09:30] nfk: in more practical news, as you can always work around getting and setting, they're a bit useless
[16:10:04] phaul: havenwood: define familiar :) I know `binding` returns the current binding which has the visiable variables
[16:10:24] havenwood: https://ruby-doc.org/core-2.5.1/Binding.html
[16:10:28] phaul: I've never used it for anything
[16:10:58] havenwood: phaul: https://bparanj.gitbooks.io/ruby-basics/content/part2/binding.html
[16:11:11] havenwood: haven't read that ^ but seems on-subject
[16:11:29] MaiconVieira: has joined #ruby
[16:11:36] phaul: well I lied I used it when I passed it to erb :)
[16:12:07] nfk: the theoretical point of them is that you have methods through which you interact with some hidden internals of a class as if it was a member variable but in reality this tends to be just a bunch of boilerplate for a variable that's essentially impossible to keep away from outside tampering
[16:12:22] havenwood: phaul: Here's a good post on Ruby Constant lookup: https://cirw.in/blog/constant-lookup
[16:12:35] NL3limin4t0r: nfk: You have to see getters and setters as the api to the variable. If some developer is going to change the internals of some class, variables may change but the getters and setters might stay the same.
[16:12:56] havenwood: phaul: A gist on Ruby method lookup: https://gist.github.com/damien-roche/351bf4e7991449714533
[16:12:58] NL3limin4t0r: The "interface" as you will.
[16:13:17] nfk: NL3limin4t0r, yeah, i avoided saying that for brevity and the fact that people who need to know this already would know it so i didn't say that ;)
[16:13:19] phaul: havenwood: thanks for the links. I will read them
[16:14:37] nfk: NL3limin4t0r, also observe that i never said there even was an internal variable just that if one has access to them they are next to impossible to keep away from whatever internals there are
[16:14:56] nfk: them being the getter and setter
[16:15:55] havenwood: nfk: I'd orphan it, garbage collect, fork it then zombie the process. You might still be able to get at it, but it'd be harder. :P
[16:16:27] havenwood: Like they say, "Ruby, you'll shoot your eye out."
[16:16:33] havenwood: Actually, do they still say that? Hah.
[16:17:43] lomex: has joined #ruby
[16:18:16] havenwood: nfk: I've definitely seen SDK gems that presume unexposed instance variables can't be gotten at. >.>
[16:19:10] patr0clus: has joined #ruby
[16:23:42] [Butch]: has joined #ruby
[16:25:23] rgr: whats the standard approach to making the ruby thats been installed in my home directory accessible to www-data for apache/passenger? install all again as user www-data? I know nothing about ruby/rails etc. I have a passenger load module and rugby env set to my local dirs in my vhost but it seems somehow wrong.
[16:32:52] NL3limin4t0r: rgr: I guess that question is better asked in the apache or pessenger irc channel (#httpd). Since it's the job of those programs to route the initial incomming requests.
[16:32:58] patr0clus: has joined #ruby
[16:33:31] nfk: havenwood, first, i doubt it will be very effective. You would need actual anti-tampering code and even then i'm not sure how effective that would be considering that people, i imagine, produce cracks for even obfuscated proprietary software without any source code publicly available. And this is not a ruby specific issue, getters and setters being misunderstood (along the entire OOP visibility fluff) as a security feature is a common part of OOP (mis)
[16:33:33] nfk: understanding and teaching
[16:37:41] clemens3: has joined #ruby
[16:38:38] lxsameer: has joined #ruby
[16:38:43] clemens3: has joined #ruby
[16:39:14] NL3limin4t0r: nfk: Ruby is pretty hackable, it's not the intention of Ruby to make anything inaccessible. It's more like the waranty on your computer. You can screw it open if you want, change parts, whatever. But if you want the "simple" and intended experiance you just use the IO given to you by the developers.
[16:40:20] NL3limin4t0r: That's why Ruby has methods like `send` and `instance_variable_{set,get}` which allows anyone access to almost anything.
[16:40:28] nfk: rgr, this is actually more about systems administration. I think it boils down to the way you interact with your ruby app. What I'd do in your place was to either try installing ruby elsewhere that would be system-wide (/usr/local comes to mind) or use the system provided ruby OR I would run a ruby application server that was only accessible locally (or from a (V)LAN, which is neat for scaling) and then have the forward facing http server send requests it does
[16:40:30] nfk: not know to the application server over either local socket or loopback interface
[16:40:59] nfk: NL3limin4t0r, again, my criticism is true for every single OOP implementation that I have ever learned
[16:41:03] s2013: has joined #ruby
[16:41:17] patr0clus: has joined #ruby
[16:42:46] nfk: furthermore i criticized the way people misunderstand due to misinformation and bad instructors what is a language abstraction feature as a security feature; finally at most i implicitly criticized languages for allowing to bypass this level of abstraction, essentially defeating it's purpose
[16:48:42] lxsameer: has joined #ruby
[16:52:15] eckhardt_: has joined #ruby
[16:55:00] nfk: s/as/for/
[16:55:26] nfk: s/it\'s/its/
[16:58:50] lxsameer: has joined #ruby
[16:59:36] NL3limin4t0r: So should car manufacturers also solder the hood of an car, just you can't tinker with the insides?
[17:00:55] havenwood: I like Ruby's anarchistic principle of trusting the programmer to behave or not at their own discretion.
[17:02:04] rgr: I is ruby specific in that I cant see how to install gems in anywhere other than my own home directory sub directories. Ah, its a locked down server. Sod it. It'll be fine pointing to my home dir. It#s not life and death.
[17:02:10] patr0clus: has joined #ruby
[17:02:17] sparr: has joined #ruby
[17:02:29] sparr: With ruby 2.3.3, I just did `gem install rubocop` and got almost enough packages to run it. It seems to also want `rubocop-rspec` installed. Is this a dependency problem?
[17:02:39] nfk: NL3limin4t0r, solder? i can chisel that easily. Maybe you meant weld? That would make it harder for themselves, also at least in EU that would be illegal if one couldn't replace bulbs or air filters easily
[17:02:46] havenwood: sparr: What the error you're running into?
[17:03:04] nowhere_man: has joined #ruby
[17:05:50] nfk: havenwood, NL3limin4t0r, again, i'm not singling out ruby for this, so chillax; all OOP implementations that I know are the same in this regard. And I never said they should disallow it for security reasons as those would be relatively easy to circumvent anyway but rather they should enforce it for the sake of staying true to OOP, if the programmer has apparently explicitly decided to embrace the use of getters and setters
[17:06:27] havenwood: nfk: I'm so chillaxed I'll go comatose if I chillax further.
[17:06:49] nfk: havenwood, i think you still have ways to go, bob (marley)
[17:07:13] havenwood: nfk: Ruby has one layer that respects object boundaries then another metaprogramming layer that doesn't care.
[17:07:22] havenwood: nfk: It's kinda a nice way to do it.
[17:07:32] havenwood: nfk: Agreed that it's also interesting to strictly enforce.
[17:07:57] havenwood: I prefer to not have hard rules though, and follow them willingly. Granted, it lets you shoot your eye out.
[17:08:38] lxsameer: has joined #ruby
[17:09:07] havenwood: sparr: I don't see where rubocop-rspec is a dep of rubocop though. It's a plugin, right?
[17:09:29] havenwood: sparr: Do you have this in your .rubocop.yml?: require: rubocop-rspec
[17:10:00] wojnar: has joined #ruby
[17:10:27] havenwood: sparr: Or is this a rake task and ruboocop-rspec is added to the task requires?
[17:10:33] havenwood: sparr: Say more about how you're running it?'
[17:10:37] jgpawletko: has joined #ruby
[17:11:02] nfk: havenwood, then why have OOP anyway? the whole point is to force a certain external API for your code, which is then undermined by the fact that anyone can just poke at the implementation internals anyway with the only meaningful difference being that you can change them and then smugly dismiss any bugreports or complaints as well deserved grievances for abusing your code - i'm sure some *cough* Red Hat *cough* people will get off from that
[17:11:12] RedNifre: has joined #ruby
[17:12:33] havenwood: nfk: The point is to provide tools that we humans can grok. OOP isn't adding anything meaningful for the computer.
[17:12:41] NL3limin4t0r: I recently encountered some anoying behaviour of Ruby. So when a module A is included in class Foo all instance method changes to A are reflected in the instances of Foo. However say I want to extend A. In my opinion the "clean" way to do this is to create a new module B and prepend that to A. However classes that already incuded A will never call the updated version in B unless they include A again, after B is
[17:12:43] NL3limin4t0r: prepended to A. My example can be found here: https://gist.github.com/3limin4t0r/fa7c4f39c55c5e75269ca7050094ca85. Is there a clean way to resolve this problem? I though of the following solutions. 1) Include to Foo instead (after the inclution of A ofcourse). 2) Don't make module B and instead just open up A. (Saving the method in a variable, than calling that from my newly defined method.)
[17:12:49] RedNifre: Hey, I'm doing "Quit script with ctrl+c" wrong and I don't know how to do it properly :(
[17:12:50] havenwood: nfk: Whether you let programmers do anything or constrain them seems like a separate question to me.
[17:13:12] havenwood: RedNifre: How can you tell it's wrong?
[17:13:39] RedNifre: See, I have this script that is continually processing a log file. When I quit it with ctrl+c it should write its state to a yaml file. This worked on linux, but on cygwin it seems to be killed too quickly sometimes so the file ends up empty.
[17:13:58] RedNifre: What I did was begin ... ensure write_to_file end
[17:14:14] RedNifre: ...and the ensure part seems to get killed sometimes before the file gets written.
[17:14:33] havenwood: RedNifre: Are you trapping SIGINT?
[17:14:37] havenwood: RedNifre: Show the code?
[17:14:54] RedNifre: So I guess I'm doing "quitting the script" the wrong way... what's the proper way to quit a script and let the script save its state to a file?
[17:15:01] RedNifre: I... might be I guess? Hang on...
[17:15:18] havenwood: NL3limin4t0r: Hrmmm
[17:15:46] RedNifre: The code is really begin (process log file by reading from STDIN) ensure (Save to yaml file) end
[17:15:48] nfk: NL3limin4t0r, this won't help you in any way but if A was a class you could extend it which is the correct way to do it, imvho; alas modules should not be extendible which is what you get for using a very old cold segmentation/sharing approach from like the 60's (or thenabout)
[17:16:26] RedNifre: It often works, but often doesn't and I either end up with an empty file or the file doesn't get updated at all... let me look up SIGINT...
[17:16:38] nfk: sorry about that typo, that was just my subconsciousness telling me i should do something about the low temperature in my room
[17:17:10] havenwood: RedNifre: https://docs.ruby-lang.org/en/2.5.0/Signal.html
[17:17:12] RedNifre: What was the semantic of pressing ctrl+c again? Was it "quit immediately!" or was it "take your time"?
[17:18:02] havenwood: RedNifre: 2 INT (interrupt)
[17:18:02] RedNifre: Okay, but conceptually speaking, what's the propper way to shut down a script that is continually processing lines from STDIN?
[17:18:16] nfk: RedNifre, from the top of my memory from a decade ago, it's finish up or something along those lines
[17:18:25] bmurt: has joined #ruby
[17:18:26] NL3limin4t0r: nfk: A is a module defined by a framework so I don't have any influence on that.
[17:18:29] havenwood: RedNifre: 2 SIGINT terminate process interrupt program
[17:18:33] havenwood: RedNifre: see: man signal
[17:18:43] RedNifre: Okay, it does say Interrupt when I quit it.
[17:18:47] lxsameer: has joined #ruby
[17:18:48] havenwood: man 3 signal
[17:18:57] sameerynho: has joined #ruby
[17:19:06] nfk: on *nix a program *MUST* disregard Ctrl+C if it's waiting on an open connection, iirc
[17:19:07] NL3limin4t0r: RedNifre: In C input is often terminated when EOF (Ctrl+D) is send.
[17:19:39] nfk: which is why NFS shares were so ungodly difficult to unmount in the olden days. and sshfs are today
[17:19:41] RedNifre: Is there a key combination for "shut down, take all the time you need"?
[17:19:56] nfk: i would not be surprised if on windows this is not the case
[17:19:57] al2o3-cr: RedNifre: you can just rescue Interrupt if pressesing C-c
[17:20:02] havenwood: or ctrl-\, SIGQUIT
[17:20:17] RedNifre: I mean, am I wrong to stop the script with ctrl+c or should the script signal "got you, give me a moment" to the OS?
[17:20:34] RedNifre: Well, I'm running the script in Cygwin so I was hoping I wouldn't have to deal with Windows specifics.
[17:20:50] RedNifre: So ctrl+\ is a more relaxed "quit"?
[17:21:16] nfk: this is my first time seeing that, no idea
[17:21:26] havenwood: RedNifre: gnu has a little writeup on signals: https://www.gnu.org/software/libc/manual/html_node/Termination-Signals.html
[17:21:49] RedNifre: I'm not sure it's even the right approach... I mean, how do you implement scripts that process a stream but can also be interrupted and save their state?
[17:22:00] nfk: RedNifre, actually, if your script handles stdio, then the normal unix way would be either q or Ctrl+D
[17:22:01] havenwood: It's a nice way to close the erlang/elixir/python/etc repl
[17:22:43] RedNifre: Well, it handles stdio throug tail -f somefile.log | ruby thescript.rb
[17:22:53] RedNifre: ...so I can't tell it q I think.
[17:23:11] nfk: q being for programs that do not need to directly process stdio as part of their core operation while Ctrl+D would be for true *nix programs as a sort of in-band control by design (they are supposed to process a single file on stdio and then quit)
[17:23:25] havenwood: RedNifre: Another signals writeup: https://programmergamer.blogspot.com/2013/05/clarification-on-sigint-sigterm-sigkill.html
[17:24:23] havenwood: Or here's one how how to actually handle a SIGINT or SIGQUIT: https://www.cons.org/cracauer/sigint.html
[17:24:48] nfk: RedNifre, then the next standard approach is using a signal and SIGINT seems reasonable as USRn are generally specific to the application and probably for operational rather than terminal signaling
[17:24:55] havenwood: You can tell by how repls handle and mishandle these that it's not universally adopted convention >.>
[17:25:09] RedNifre: Well, it sounds like SIGINT is "terminate gracefully" so I'm surprised that it gets killed so quickly that it sometimes can't even write a small yaml file.
[17:25:33] havenwood: RedNifre: You can make it terminate gracefully by trapping SIGINT and making sure the grace part happens!
[17:25:36] nfk: RedNifre, assuming you're correctly trapping SIGINT, then it must be either cygwin or windows specific, sorry
[17:26:44] nfk: from what i have seen, on *nix the first SIGINT is left to the app and the second either has some higher up handler that's very ubiquitous or is provided by the platform itself
[17:26:51] RedNifre: I'm not sure if I'm correctly trapping SIGINT, it's really just `begin ... ensure (write to file) end`
[17:27:13] nfk: that having been said, true *nix programs that wait for closing of all open connections will regard any number of SIGINTs
[17:27:26] RedNifre: ACTION looks up how to correctly trap SIGINT int ruby...
[17:28:00] nfk: RedNifre, that's just from my memory as i have never written anything like that but i think you're supposed to handle SIGINT yourself if you do not want your runtime or something handling it for you
[17:28:45] nfk: probably something like it moving from your app to the runtime to language to stdlib to kernel? just a wild guess
[17:28:53] lxsameer: has joined #ruby
[17:28:56] havenwood: RedNifre: Check out the `Signal.trap :SIGINT do` here: https://docs.ruby-lang.org/en/2.5.0/Signal.html
[17:29:02] mikecmpbll: has joined #ruby
[17:29:19] RedNifre: Well, what exactly does "ensure" do in this case? does it first tell the OS "I don't care, do what you must!" and then tries to run the following code whereas `rescue Interrupt` would tell the OS "I'm hearing you, give me a sec here!"?
[17:30:02] havenwood: RedNifre: Ruby also has an #on_exit
[17:30:09] havenwood: RedNifre: ensure has to do with error handling, but doesn't know about signals
[17:30:27] knight33: has joined #ruby
[17:30:34] havenwood: RedNifre: https://ruby-doc.org/core-2.5.1/Kernel.html#method-i-at_exit
[17:30:51] havenwood: #at_exit I mean, heh
[17:31:00] FrankyCyborg: has joined #ruby
[17:31:37] nfk: RedNifre, i think *nix signal handling conceptually is a lot like Exception handling - if you catch it, it's then up to you to handle the situation, possibly including not handling a repeated SIGINT if the user becomes impatient
[17:32:47] RedNifre: Well, it feel like "ensure" kinda sees the "exception" but does not "catch" it so the OS doesn't know that the script is trying to do something... if I understand it correctly then `begin ... rescue SystemExit, Interrupt ... end` should work instead.
[17:35:00] havenwood: RedNifre: Mmm, good point - you could rescue things we tend not to instead of signal trap. I guess that makes sense when you only want to trap on a particular error.
[17:35:09] havenwood: RedNifre: I mean on a particular segment of code*
[17:36:05] havenwood: RedNifre: Do you want to handle all exits from your program (#at_exit), all int signals from your program (#trap) or just signals in a specific segment of code (the solution you mention).
[17:37:11] havenwood: RedNifre: This'd be an interesting thing to do a writeup on.
[17:37:53] RedNifre: Well... It's just that I have the script running locally on my machine, I want to quit it easily and I want it to continue where it left off when I start it again, so it should save its state when I quit it.
[17:38:24] RedNifre: I'll see if it works now...
[17:38:39] lxsameer: has joined #ruby
[17:39:14] duderonomy: has joined #ruby
[17:41:38] nfk: RedNifre, in that case, you should also use a certain pattern to ensure that the file does not get corrupted even on forced termination. i'm quite certain there's a certain Linux pattern you're supposed to use, i just can't seem to find it
[17:42:15] snickers: has joined #ruby
[17:44:17] jottr: has joined #ruby
[17:44:43] za1b1tsu: has joined #ruby
[17:46:21] duderonomy: has joined #ruby
[17:48:43] lxsameer: has joined #ruby
[17:52:12] nfk: RedNifre, i could not find the pattern, so take this with a grain of salt but I'd do something like this: 1) periodically create a new file (rather than overwriting the old one), 2) wait for sync to finish on it, 3) mv the previous version of log to .old (i.e. foo.log.old), 4) mv the new version to be the main file and 5) rm the old version. Optionally you might do a filesystem sync after all of this. Do note that this is (probably) safe only on GNU/Linux!
[17:53:15] nfk: for obvious reasons this is a generic pattern that is not feasible with either very large files, a system serving a lot of I/O and probably few more cases even on GNU/Linux
[17:56:14] nertzy: has joined #ruby
[17:57:56] ricer2: has joined #ruby
[17:58:44] lxsameer: has joined #ruby
[17:59:02] nfk: oh, and do note that it's not impossible for the mv foo.log foo.log.old; rm foo.log.old to happen before mv foo.log.new foo.log.old leaving you with the new but not the main log file!
[17:59:43] apeiros_: has joined #ruby
[18:00:15] nfk: also you probably need to re-open the main log if you're also reading from it as on *nix it will likely be pointing to the old file that you deleted
[18:01:15] nfk: *happen before mv foo.log.new foo.log
[18:01:22] cliluw: has joined #ruby
[18:07:15] dviola: has joined #ruby
[18:08:47] lxsameer: has joined #ruby
[18:10:47] tubbo: has joined #ruby
[18:13:49] SeepingN: has joined #ruby
[18:14:28] jottr: has joined #ruby
[18:16:16] tubbo: has joined #ruby
[18:16:19] NL3limin4t0r: If every log entry is just one line it's as simple as checking for the newline character at the end of the file. If it's there the last line was written succesfully, if it's not there the last line got currupted and should be overwritten. If a log entry may contains more than one line you can still use this, since the likelyhood of breaking after exactly a newline is not that large. However if mind the fact
[18:16:21] NL3limin4t0r: that in a rare case a few lines could not be there you'll have to look for another aproach.
[18:17:42] sanscoeur: has joined #ruby
[18:18:51] lxsameer: has joined #ruby
[18:21:19] NL3limin4t0r: I've to go, it's getting late.
[18:24:59] knight33: has joined #ruby
[18:25:18] RougeR: has joined #ruby
[18:25:52] Inside: has joined #ruby
[18:26:12] Inside: Q: How is it possible for Hash to have an O(1) complexity for doing look ups?
[18:28:11] Inside: I understand if you could take a key and hash it to like a ...n-bit value .. then you could store offset pointers in an n-bit sized array so you could immediately jump to the data
[18:28:12] MyMind: has joined #ruby
[18:28:54] lxsameer: has joined #ruby
[18:29:49] aspiers: has joined #ruby
[18:30:28] cats: has joined #ruby
[18:34:25] apeiros_: Inside: https://en.wikipedia.org/wiki/Hash_table
[18:35:00] apeiros: basically by having N buckets, and hashing the key to a numerical value in the range 0...N
[18:35:22] havenwood: Inside: Here's a nice little writeup: https://blog.heroku.com/ruby-2-4-features-hashes-integers-rounding#better-hashes
[18:35:49] baweaver: I tab over to google and the two ninjas strike
[18:36:09] apeiros: but… we left you like 8 minutes! you slacker!
[18:36:15] apeiros: and moin ;-)
[18:37:13] havenwood: Inside: And a pure-Ruby implementation of SipHash 13 - if you'd like to see what that's about: https://github.com/havenwood/digest-sip_hash/blob/master/lib/digest/sip_hash.rb
[18:37:50] havenwood: I like SipHash's "pseudo randomly generated bytes"... >.>
[18:37:59] havenwood: https://github.com/havenwood/digest-sip_hash/blob/master/lib/digest/sip_hash.rb#L38-L41
[18:38:49] lxsameer: has joined #ruby
[18:38:55] havenwood: Or the C SipHash implementation that Ruby actually uses: https://github.com/ruby/ruby/blob/4444025d16ae1a586eee6a0ac9bdd09e33833f3c/siphash.c
[18:39:10] Inside: havenwood: superneat, didn't know that's how hashes worked
[18:39:35] Inside: so it's not quiiiite O(1) but O(1) + O(n<~11)
[18:40:19] apeiros: it is O(1). n relates to the number of elements. if you consider keylength too, it's no longer O(1).
[18:41:08] Inside: Well - it hashes the object to get a bin# then it iterates through every object in the bin which can var, no?
[18:41:34] apeiros: that's one possible implementation to handle collisions, yes.
[18:42:08] desperek: has joined #ruby
[18:44:15] Inside: I've been using hashes incorrectly :D
[18:44:51] Inside: https://gist.github.com/Insood/daf2a783e25657ee5ad3038715568b4b
[18:46:06] Inside: or is there a better way to check for presence of a key in a data set?
[18:47:10] Inside: ah looks like Set uses hash internally as well so I've been doing it right
[18:47:14] apeiros: that depends. in most generic cases, hash/set will be the fastest. but note that O(1) isn't necessarily faster than e.g. O(log(n)) for a given n.
[18:48:34] Inside: and actually looks like w/ 1M elements Set is the slowest..
[18:48:46] lxsameer: has joined #ruby
[18:49:10] knight33: has joined #ruby
[18:49:29] aspiers: has joined #ruby
[18:50:20] apeiros: that benchmark you posted doesn't test performance of key presence testing, though.
[18:50:39] Inside: true true
[18:52:25] s2013: has joined #ruby
[18:53:13] ua: has joined #ruby
[18:53:55] cd: has joined #ruby
[18:58:49] lxsameer: has joined #ruby
[19:02:44] Inside: https://gist.github.com/Insood/f1ea853dcbb1772150107fac8dfe0267
[19:03:24] Inside: Looks like it's still faster to create a hash for key lookup than it is to use a Set :(
[19:03:29] Inside: er - key storage
[19:03:30] Inside: with no lookup
[19:04:19] Inside: Probably uses more memory though
[19:08:48] lxsameer: has joined #ruby
[19:09:07] cd: has joined #ruby
[19:10:09] knight33: has joined #ruby
[19:15:55] sauvin_: has joined #ruby
[19:17:40] Inside: Ah, set uses hash[k] = v to insert stuff into itself
[19:18:53] lxsameer: has joined #ruby
[19:21:16] Inside: ah array.to_hash dives into C
[19:23:19] herbmillerjr: has joined #ruby
[19:28:10] sauvin: has joined #ruby
[19:29:22] lxsameer: has joined #ruby
[19:35:30] DTZUZO: has joined #ruby
[19:36:05] herbmillerjr: has joined #ruby
[19:43:11] LiftLeft2: has joined #ruby
[19:53:30] code_zombie: has joined #ruby
[19:58:31] nertzy: has joined #ruby
[19:59:18] aspiers: has joined #ruby
[20:03:04] TheBloke-: has joined #ruby
[20:05:01] thy0: has joined #ruby
[20:11:39] DTZUZO: has joined #ruby
[20:13:37] alem0lars: has joined #ruby
[20:18:35] herbmillerjr: has joined #ruby
[20:26:23] herbmillerjr: has joined #ruby
[20:30:08] sanscoeur: has joined #ruby
[20:31:34] sauvin: has joined #ruby
[20:51:44] sauvin: has joined #ruby
[21:09:43] nfk: Inside, in my noob experience code is either way too slow or fast enough that you don't care about actual speed ;)
[21:11:14] nmuntz: has joined #ruby
[21:14:47] nfk: after all, i literally have a CPU from 2008 if not earlier yet it's currently at sub 10% on average (with immediate per-core use often 0.0%) and both graphical and video cores, and even Gen 1 PCIe at 0% utilization even though I'm currently running a modern web browser, a compositing desktop and a capistrano webapp all while chatting on irc
[21:15:33] nfk: meanwhile a previous generation ultrabook with discrete graphis would run laps around this system
[21:22:25] IanMalcolm: has joined #ruby
[21:23:12] nmuntz: hi! so I inherited a ruby script that was working before and now it's giving errors. I'm not very familiar with ruby so I was hoping someone could shed some light on this code: https://pastebin.com/iPAtnJeq - at the bottom of the paste is the error i'm getting
[21:23:13] ruby[bot]: nmuntz: we in #ruby do not like pastebin.com, it loads slowly for most, has ads which are distracting and has terrible formatting. Please use https://gist.github.com
[21:24:42] nfk: ah, so that's why people don't like it
[21:31:40] RedNifre: has joined #ruby
[21:34:50] lxsameer: has joined #ruby
[21:35:15] icarus: has joined #ruby
[21:38:26] gnufied: has joined #ruby
[21:38:55] clemens3: has joined #ruby
[21:39:24] jottr: has joined #ruby
[21:42:42] alireza: has joined #ruby
[21:47:20] nmuntz: so inside a loop I have items[trophy.program][trophy.award] << Item.new(order, trophy) and apparently when this is encountering a nul element that's causing the exception. how can i handle this scenario?
[21:49:18] Azure: has joined #ruby
[21:50:52] RedNifre: has joined #ruby
[21:52:35] nfk: 1) check that it's not nil: nil.nil? which will return true if it is nil. 2) check that element.respond_to? :method_name or 3) just try it and handle the NoMethodError exception if it's thrown at you OR 4) there might be a bug in your code due to changes and a class member that's not supposed to be nil is not being assigned its correct value
[21:52:39] cagomez: has joined #ruby
[21:52:49] nfk: there's actually more ways but they'll just be different variants of 1 and 2
[21:53:27] nfk: btw, it's said that the most ruby way is to just try and handle exceptions
[21:53:45] raulp: has joined #ruby
[21:55:58] SeepingN: rescue next
[21:56:45] Inside: nfk: Ugh I'm trying to pull in ~100k records from two different databases and Set A - Set B
[21:56:53] Inside: Which is why I was trying to figure out what's faster
[21:57:08] Inside: although the data loading from one database is still the bottleneck (Like.. ~10S)
[21:57:43] nfk: Inside, does that mean that you're trying to solve a non-existing issue?
[21:58:33] nfk: also the number of records is pretty low as far as databases go but i'm not sure if the same goes for set operations (not my field of expertise though)
[21:59:00] nfk: assuming by record you don't mean something like a whole document
[21:59:54] mikecmpbll: has joined #ruby
[22:00:09] weaksauce: has joined #ruby
[22:00:43] nfk: Inside, actually have you considered just doing it in sql?
[22:00:50] Inside: Well one of the queries joins about 3 tables of like 20M rows together
[22:00:54] Inside: so it has a tendency to time out
[22:01:11] Inside: Unfortunately that's the ERP database so I can't do anything to it
[22:03:17] nfk: if synchronicity is not an issue how about just getting the data you need from the slow database into some temporary database and use that?
[22:04:10] SeepingN_: has joined #ruby
[22:04:20] Inside: This is for a rails application
[22:04:26] Inside: so I am using MemoryStore to cache data for like 30 minutes or so
[22:04:54] nfk: ah, is that the slow one?
[22:05:09] nfk: oh wait, it's supposed to be very fast
[22:05:51] sauvin: has joined #ruby
[22:06:12] nfk: ACTION feels a bit lost on what exactly Inside is trying to accomplish by optimizing an alleged non-bottleneck
[22:08:10] Radar: maybe hes doing a speedrun ;)
[22:08:25] Radar: any% rails request
[22:08:33] Inside: yes basically
[22:10:05] Inside: The original question was what to do with the data once I had it out of the database -- instead of doing an O(N^2) matchup -- iterate through one list of items and then check to see if it's in the other hashmap
[22:10:41] Inside: Now I'm back to the original issue of fiddling with the data coming from the database
[22:11:35] DTZUZO: has joined #ruby
[22:14:16] Nicmavr: has joined #ruby
[22:16:31] Inside: So then - this turns into more of a database question
[22:16:43] nfk: we'll see
[22:16:58] Inside: we're already there :D
[22:17:07] nfk: i'm currently feeling scared as my irb just got 33000 entry hash
[22:17:15] nfk: that was.. a sight
[22:17:27] nfk: can i do 67k?
[22:17:56] nfk: to get to 100k hash
[22:18:12] nfk: so far my RAM seems to be completely in check which was the scary part
[22:19:00] nfk: first one down, time for the second one
[22:19:13] RedNifre: has joined #ruby
[22:19:24] nfk: actually, my keys looks pathetic
[22:19:50] nfk: oops.... i feel stupid
[22:21:14] nfk: ho, ho, i can hear the cpu fan spinning up
[22:22:18] nfk: yeah, this time my ram is actually growing
[22:22:59] RedNifre_: has joined #ruby
[22:24:55] nfk: Inside, sorry, i don't think i'll be able to try what you're doing even with a simple hash as i'm nearing swapout point yet i'm less than 2/3 into the first hash generation
[22:25:31] nfk: had to abort XD
[22:25:50] nfk: have you tried it on your end?
[22:26:15] Inside: I have no idea what you're talking about
[22:27:06] nfk: h = {}; 100000.times.map {|n| h.merge!({Random.rand(1000000) => n})}
[22:28:00] nfk: this should generate a hash with 100k elements. unfortunately i suspect your values will be more than simple integers but at least that should give you a feel for what you'll be up against
[22:29:28] nfk: did i get something wrong?
[22:30:07] Inside: I think it's simpler than that
[22:30:29] nfk: do go on
[22:31:15] Inside: I'm quering two databases - one set of data goes into a list, the second into a hash. Then I'm seeing if each record in the last has a matching record in the hash
[22:31:24] Inside: I mean - it works, it's just slower than I want
[22:31:25] Inside: ACTION shrugs
[22:31:57] Inside: it's an intranet website for internal use so it bums me out to see timeout messages on the server
[22:31:58] raul782: has joined #ruby
[22:34:32] Inside: But - that's more of a database/middleware/etcetc question than anything
[22:41:26] Inside: ACTION mozies on over to #sql
[22:50:52] alireza: has left #ruby: ("WeeChat 2.1")
[22:53:21] s2013: has joined #ruby
[22:56:10] white_lilies: has joined #ruby
[23:08:52] nfk: this is some sick capability: (Pathname.new("/home/user/test 1") / "../test 2/../test 3").cleanpath
[23:09:17] icarus: Hi all, what is the best way to validate json from a resquest in ruby?
[23:09:43] icarus: I've looked at 'json' and 'json-schema', but neither work
[23:10:13] agent_white: has joined #ruby
[23:10:40] icarus: I'm just looking for a quick elegant way to validate json along a route in sinatra
[23:12:05] IanMalcolm: has joined #ruby
[23:12:43] baweaver: icarus: One _could_ make contracts with Qo for hashes
[23:13:15] baweaver: Let's take a look at this API response: https://jsonplaceholder.typicode.com/users
[23:15:57] nfk: isn't the whole point of JSON to have a data format that can be parsed without validating it?
[23:16:04] jottr: has joined #ruby
[23:16:33] baweaver: Depends what they mean by validate
[23:16:40] baweaver: validate the text, or the parsed content?
[23:16:59] baweaver: icarus: could you clarify?
[23:16:59] nfk: i'm very certain he meant field presence, data types and possibly absence
[23:17:51] nfk: so basically that the client response more or less fits the bill, at which point the whole point of having a ubiquitous format that can be flexible in it's format and content is out the window, imho
[23:17:52] SeepingN_: the more you assume incoming data is safe, the larger your vulnerabilities
[23:18:27] im0nde: has joined #ruby
[23:18:35] xfbs: has joined #ruby
[23:19:20] baweaver: https://dpaste.de/wTmC
[23:19:47] baweaver: (note the symbolize_names: true)
[23:20:06] baweaver: nfk: That's rather backwards
[23:20:19] baweaver: The entire point of API responses and requests is a consistent format
[23:20:22] nfk: baweaver, also sorry that only now i noticed your use of singular "them". let me tip my virtual hat to you
[23:20:38] nfk: it seems i'm really getting tired
[23:21:41] nfk: baweaver, validating format and validating schema compliance are two different things
[23:22:03] nfk: i doubt invalid JSON would parse without an exception
[23:22:15] baweaver: depends on what you mean by invalid :)
[23:22:47] nfk: i'd love to give examples but i really should get back to my app before i get any more tired
[23:23:13] baweaver: http://seriot.ch/parsing_json.php
[23:23:19] baweaver: Short version, JSON parsers aren't exactly 100% consistent in shenanigans
[23:23:19] DTZUZO_: has joined #ruby
[23:23:39] baweaver: Though I think we're really reading too much into this one
[23:25:10] nfk: baweaver, is this the next version of: "validating e-mail addresses: how hard can that be? TM"?
[23:25:40] nfk: would be funnier if 90% of university professors didn't think it was easy
[23:26:28] s2013: has joined #ruby
[23:27:27] baweaver: When doing university assignments, assume permissive
[23:27:36] baweaver: It saves a ton of time, and is probably what said professor wants
[23:31:27] nfk: i mean it in general: with the exception of my compsec professor (who was a literal professor and board member) no one seemed to have even a hunch that e-mail address validation is one deep rabbit hole
[23:35:30] lxsameer: has joined #ruby
[23:36:07] baweaver: Some rabbits are quite simply not worth chasing down a hole
[23:38:06] Xeago_: has joined #ruby
[23:39:40] ZzZombo_: has joined #ruby
[23:41:31] sheepman: has joined #ruby
[23:45:19] nfk: baweaver, so i ended up reading good portion of that website. thanks for the link, that was quite interesting. also nowhere near as bad as e-mail validation from what i recall
[23:46:23] baweaver: Regex and finite automata are fun too.
[23:46:41] baweaver: https://swtch.com/~rsc/regexp/regexp1.html
[23:46:59] nfk: oh, they're fun to just write. forget parsing :D
[23:47:30] baweaver: I should make a Thompson NFA implementation later, but that requires me to learn C extensions
[23:47:37] baweaver: which I really really really really don't want to do.
[23:48:00] nfk: nothing quite like writing in a programming language few know well and one that very different from your run of the mill languages
[23:48:07] nfk: what could possibly go wrong with that, right? TM
[23:48:16] nfk: *that's
[23:48:33] thy0: has joined #ruby
[23:48:35] baweaver: Consider also that most of Ruby C is macros on top of C, so you're not really writing vanilla C either
[23:50:07] baweaver: Once I'm done writing this book, I may go back and force myself to write something on that too
[23:50:15] nfk: i head the expert advise of leaving C to the handful of professionals that can be trusted with not making horrific mistakes and cross my fingers that linux kernel is safe enough
[23:50:36] baweaver: "An Illustrated Guide to Ruby - Appendix C" seems like enough of a trollish name :D
[23:51:22] baweaver: Might have to ask Pat if he'd be willing to join in on it.
[23:51:48] baweaver: Ruby Under a Microscope gets close to a lot of it
[23:56:01] s2013: has joined #ruby
[23:56:38] baweaver: https://silverhammermba.github.io/emberb/c/
[23:56:39] im0nde: has joined #ruby
[23:56:43] baweaver: and that's a perpetual gold mine
[23:58:33] sheepman: has joined #ruby
[23:59:53] DTZUZO_: has joined #ruby