« Back to channel list

#ruby - 30 May 2017

« Back 1 day Forward 1 day »
[00:02:37] gothicsouth: has joined #ruby
[00:07:39] Pongles: has joined #ruby
[00:09:00] Pongles: Radar, sorry to bug you again, but do you know if there is a way to flush data sent to the server without blocking?
[00:11:52] BSaboia: has joined #ruby
[00:12:46] milardovich: has joined #ruby
[00:13:31] brent__: has joined #ruby
[00:15:19] nobitanobi: has joined #ruby
[00:18:11] Pongles: I am trying to mimic a telnet server but I don't know a good way to grab the negotiation at the start
[00:25:38] LastWhisper____: has joined #ruby
[00:26:23] Radar: Pongles: no sorry I don't know that
[00:34:26] mrconfused: has joined #ruby
[00:39:21] olivier__: has joined #ruby
[00:41:06] ResidentBiscuit: has joined #ruby
[00:42:39] olivier__: has joined #ruby
[00:45:06] charliesome: has joined #ruby
[00:49:46] mrconfused: has joined #ruby
[00:55:32] nadir: has joined #ruby
[00:56:45] sneakerhax: has joined #ruby
[00:58:19] claw: has joined #ruby
[00:58:25] olivier__: has joined #ruby
[01:00:07] apparition: has joined #ruby
[01:02:19] Jameser: has joined #ruby
[01:02:23] brent__: has joined #ruby
[01:03:33] chopin: has joined #ruby
[01:06:25] alveric3: has joined #ruby
[01:07:47] knamehost: has joined #ruby
[01:10:00] eightlimbed: has joined #ruby
[01:16:34] PorcoRex: has joined #ruby
[01:16:38] PorcoRex: Good evening.
[01:21:14] erlend: has joined #ruby
[01:21:44] knamehost: hi . where ca i find a good read about ruby ... tuts vids etc
[01:23:39] PorcoRex: knamehost, there are several good resources. Are you a developer already? A beginner?
[01:23:39] HoierM: has joined #ruby
[01:27:31] demio: has joined #ruby
[01:29:54] Guest6988: has joined #ruby
[01:31:10] knamehost: PorcoRex, beginner my friend
[01:31:25] 5EXAA2YP3: has joined #ruby
[01:31:30] knamehost: im going to deve too as well
[01:31:45] jusa: has joined #ruby
[01:32:15] charliesome: has joined #ruby
[01:32:19] Guest6988: has joined #ruby
[01:35:38] PorcoRex: knamehost, this is probably a nice one to step your toe: http://poignant.guide/
[01:36:26] knamehost: ty PorcoRex
[01:36:33] PorcoRex: knamehost, sure, enjoy.
[01:41:19] jakew: has joined #ruby
[01:42:00] d^sh: has joined #ruby
[01:44:48] Uranio: has joined #ruby
[01:45:32] jrafanie: has joined #ruby
[01:47:35] Jameser: has joined #ruby
[01:51:14] ResidentBiscuit: has joined #ruby
[01:51:24] Arahael: Curious how ruby has both ==, and ===, if == already compares object identity.
[01:53:30] PorcoRex: Arahael, === is case equality. The operator can be overridden to give "better" matches, generally (and, in my opinion, preferably) on case statements.
[01:54:55] Uranio: has left #ruby: ("while you read this, a kitty dies")
[01:54:57] Arahael: PorcoRex: It's just a curiousity compared to say, javascript.
[01:55:24] Arahael: PorcoRex: "==" there is 'somewhat equal', whereas '===' makes it more likely that the types themselves are equal as well
[01:55:28] PorcoRex: Arahael, it's completely different from JS in that sense. Not even close.
[01:55:55] Arahael: PorcoRex: Indeed. Not neccessarily a bad thing - the javascript situation is horrible.
[01:55:57] elomatreb: You generally don't use === yourself, ever
[01:56:14] Arahael: elomatreb: Good to know. (In ruby)
[01:56:27] mrconfused: has joined #ruby
[01:59:17] Radar: Then there's the fabled ====
[02:02:01] PorcoRex: Radar, seriously? I just read it was reserved for future use.
[02:02:17] Arahael: Radar: I thought that was only for the haskell devs? ;)
[02:03:55] demio: has joined #ruby
[02:04:22] GodFather: has joined #ruby
[02:10:16] kies: has joined #ruby
[02:18:22] AndBobsYourUncle: has joined #ruby
[02:20:20] arescorpio: has joined #ruby
[02:20:24] genpaku: has joined #ruby
[02:26:18] belmoussaoui: has joined #ruby
[02:29:31] eightlimbed: can someone explain how this determines whether a number is prime or not?
[02:29:35] eightlimbed: (2..n/2).none? { |i| n % i == 0}
[02:29:57] eightlimbed: why it is n/2 and not n-1
[02:30:47] elomatreb: A number larger than the half of n trivially can't divide it evenly
[02:31:16] belmoussaoui: has joined #ruby
[02:33:10] roamingdog: has joined #ruby
[02:33:45] jgpawletko: has joined #ruby
[02:34:58] cyphase: has joined #ruby
[02:39:58] roamingdog: has joined #ruby
[02:43:46] Uranio-235: has joined #ruby
[02:47:34] mrconfused: has joined #ruby
[02:47:39] pb122: has joined #ruby
[02:51:28] jusa: has joined #ruby
[02:52:55] charliesome: has joined #ruby
[02:59:57] charliesome: has joined #ruby
[03:14:04] mrconfused: has joined #ruby
[03:23:38] quazimodo: has joined #ruby
[03:29:36] quazimodo: do we have file local constants in ruby?
[03:30:07] Nilium: Not that I'm aware of, unless you add something like const_missing and check the file and so on
[03:37:17] gix: has joined #ruby
[03:37:56] _sfiguser: has joined #ruby
[03:38:46] segmond: has joined #ruby
[03:39:54] kies: has joined #ruby
[03:40:43] gothicsouth: has joined #ruby
[03:41:09] harfangk: has joined #ruby
[03:48:36] tristanp: has joined #ruby
[03:56:31] olson86: has joined #ruby
[04:00:45] cgfbee: has joined #ruby
[04:03:51] __Yiota: has joined #ruby
[04:10:09] rohitpaulk: has joined #ruby
[04:11:27] tristanp: has joined #ruby
[04:16:39] nobitanobi: has joined #ruby
[04:16:51] Jameser: has joined #ruby
[04:28:09] Jameser: has joined #ruby
[04:28:45] belmoussaoui_: has joined #ruby
[04:35:52] renchan: has joined #ruby
[04:38:16] TomyLobo: has joined #ruby
[04:41:58] Jameser: has joined #ruby
[04:46:08] uZiel: has joined #ruby
[04:51:16] uZiel: has joined #ruby
[04:55:29] Mortomes|Train: has joined #ruby
[04:57:59] zacts: has joined #ruby
[05:00:07] zenspider: Pongles: did you get stuff figured out?
[05:00:56] Pongles: In regards to the telnet negotiation?
[05:02:44] djbkd: has joined #ruby
[05:03:15] __Yiota: has joined #ruby
[05:03:17] mim1k: has joined #ruby
[05:05:32] jusa: has joined #ruby
[05:15:40] tristanp: has joined #ruby
[05:18:21] nbering: has joined #ruby
[05:18:29] cam27: has joined #ruby
[05:20:46] Radar: Pongles: ^
[05:21:29] Pongles: I have yet to figure that out, nor have I had a chance to work on it since
[05:21:56] Pongles: I tried doing a client.read() before the first get but that appears to not work as intended
[05:22:40] anisha_: has joined #ruby
[05:23:16] Radar: zenspider: Any idea how to make Pongles code not block? I tried coming up with an answer this morning but I couldn't.
[05:23:24] Radar: I'd like to see what you could come up with
[05:23:40] nbering: I have a question that's about something I see in Rails a lot, but is actually a language question. I often see code in a class like ActiveRecord's has_many function, and it looks almost like an include, but it feels more like a function call. What's actually happening when that's called? Speaking broadly of the pattern, not the specific example.
[05:24:30] Pongles: here is what my code currently looks like: https://gist.github.com/anonymous/b4e4e5801d5785c2bbe0b6c0721c244c
[05:24:41] roshanavand: has joined #ruby
[05:25:05] Radar: nbering: it's calling a class function.
[05:25:14] Radar: class method*
[05:25:59] zenspider: a class method that is generating other methods on the class
[05:26:16] Radar: https://gist.github.com/radar/0e38eab3c1033af9a794706a80dc04af
[05:27:03] nbering: Ok. I thought as much. When does that execute? Is it when Ruby evaluates the class definition, or when an instance is created?
[05:27:04] Radar: nbering: here's the start of that particular rabbit hole: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations.rb#L1395-L1398
[05:27:17] Radar: nbering: when Ruby evaluates the class definition.
[05:27:23] zenspider: Pongles: I don't know what the problem is. "not work as intended" is vague
[05:27:33] aupadhye: has joined #ruby
[05:27:53] Pongles: The client.read() appears to block until newline from client
[05:28:14] zenspider: yes... working as intended
[05:28:17] Pongles: as I am using port 23 to mimic a telnet server, the clients are sending negotiation characters at the start of the connection
[05:28:28] Radar: zenspider: I think Pongles wants the program to close the connection immediately when the client closes their connection. Right now it just waits for further input.
[05:28:31] nbering: Radar: Thank you very much. Smells like a rabbit hole indeed, but now I know where to look for it.
[05:28:35] Pongles: and I am trying to make it so they don't get added to the userid variable
[05:28:40] Pongles: @Radar, no
[05:28:48] Radar: ok, I'll let you explain it
[05:28:57] Pongles: I thought I did
[05:29:14] zenspider: `client.gets.chomp.to_s` is blocking code. as defined.
[05:30:27] Pongles: client.gets.chomp.to_s is not client.read
[05:30:49] Pongles: I have been having troubles trying to ignore the negotiation characters at the start of the connection from the client
[05:30:59] roshanavand: has joined #ruby
[05:31:02] Pongles: I tried client.read at the start to swallow them, but it didn't work
[05:31:03] zenspider: doesn't matter. They BOTH block, *AS DEFINED*
[05:31:17] kies: has joined #ruby
[05:31:24] Pongles: That's not the problem though
[05:31:28] karlding: has joined #ruby
[05:31:48] Pongles: The problem is that I need to figure out a way to ignore the negotiation characters at the start of the connection that the client sends
[05:32:02] zenspider: you can't ignore them. try again
[05:32:13] roshanavand1: has joined #ruby
[05:32:15] zenspider: they're sent over an IO that you're trying to use...
[05:32:24] zenspider: what do you really want?
[05:32:26] Pongles: did you ping me about my issue hours later just to troll me?
[05:33:06] zenspider: or you could do better than spend 10 minutes NOT describing your problem, and when obvious issues are brought up, you could address them
[05:33:13] roshanavand: has joined #ruby
[05:33:25] zenspider: you can't "ignore" the negotiation. You have to do something with the IO to get the meat you do want
[05:33:43] Pongles: I am fine with *getting* the characters and then doing nothing with them
[05:33:47] zenspider: so just to be really clear... blocking is NOT the issue at all?
[05:33:49] Pongles: I just need them to not be part of userid
[05:34:03] zenspider: are they fixed length? or fixed format?
[05:34:05] Pongles: blocking was never the main issue, it was just a side effect of the method I tried to fix
[05:34:28] Pongles: they are not fixed length, but they do have a standard format
[05:34:35] roshanavand: has joined #ruby
[05:35:08] zenspider: so you'll need to write some sort of (no-op) parser for it, reading n chars at a time (even 1) until it is gone
[05:35:50] roshanavand: has joined #ruby
[05:35:53] zenspider: IO has #ungetc so you can put BACK a char if you go past the last negotiation sequence
[05:36:35] zenspider: even something as dumb as: c = io.getc until c == "\0";
[05:36:50] zenspider: what's the format?
[05:37:48] Pongles: It's this: http://mud-dev.wikidot.com/telnet:negotiation
[05:38:09] Pongles: they basically just add the characters for more options from what I've seen
[05:39:18] Pongles: it always starts the same but could end with anything
[05:40:20] zenspider: is there some reason why you're NOT using net/telnet? or at least stealing from it
[05:41:05] Pongles: the ruby telnet implementation appears to be clientside only
[05:41:18] Pongles: if I am wrong then I'd be more than willing to utitlize it
[05:41:26] zenspider: still seems to have all of this negotiation handling in it
[05:41:39] zenspider: string.gsub(/#{IAC}([#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]| [#{DO}#{DONT}#{WILL}#{WONT}] [#{OPT_BINARY}-#{OPT_NEW_ENVIRON}#{OPT_EXOPL}]| #{SB}[^#{IAC}]*#{IAC}#{SE})/xno) do ...
[05:43:23] zenspider: https://www.ruby-forum.com/topic/75391 james gray knows his shit
[05:46:25] Pongles: okay, I will look into that
[05:53:55] gothicso_: has joined #ruby
[05:55:59] acemo_: has joined #ruby
[05:56:15] rgr: has joined #ruby
[05:58:09] kies: has joined #ruby
[05:58:49] rohitpaulk: has joined #ruby
[06:06:24] Cohedrin: has joined #ruby
[06:08:59] olivier__: has joined #ruby
[06:09:04] zacts: has joined #ruby
[06:21:17] gothicsouth: has joined #ruby
[06:23:29] djbkd: has joined #ruby
[06:25:04] Mortomes|Work: has joined #ruby
[06:26:07] DoubleMalt: has joined #ruby
[06:28:23] Gucciferal: has joined #ruby
[06:28:37] ahrs: has joined #ruby
[06:28:45] anisha: has joined #ruby
[06:31:03] cfec0b8d: has joined #ruby
[06:33:40] mikecmpbll: has joined #ruby
[06:35:09] conta: has joined #ruby
[06:45:11] roamingdog: has joined #ruby
[06:46:01] roamingdog: has joined #ruby
[06:46:12] nofxxxx: has joined #ruby
[06:46:45] roamingdog: has joined #ruby
[06:47:36] roamingdog: has joined #ruby
[06:48:15] Emmanuel_Chanel: has joined #ruby
[06:48:20] roamingdog: has joined #ruby
[06:49:15] govg: has joined #ruby
[06:51:01] mtkd: has joined #ruby
[06:51:34] roshanavand: has joined #ruby
[06:57:11] mark_66: has joined #ruby
[06:58:18] roshanavand: has left #ruby: ()
[07:03:35] teclator: has joined #ruby
[07:03:48] mim1k: has joined #ruby
[07:06:25] jusa: has joined #ruby
[07:08:25] ltem: has joined #ruby
[07:09:44] tAn: has joined #ruby
[07:11:03] jaruga________: has joined #ruby
[07:12:58] aufi: has joined #ruby
[07:14:48] mim1k: has joined #ruby
[07:15:20] romank: has joined #ruby
[07:17:04] TomyWork: has joined #ruby
[07:18:05] jgt: has joined #ruby
[07:20:46] glejeune: has joined #ruby
[07:21:06] erlend: has joined #ruby
[07:22:08] olivier__: has joined #ruby
[07:32:07] erlend: has joined #ruby
[07:32:08] mikecmpbll: has joined #ruby
[07:34:37] nowhere_man: has joined #ruby
[07:34:57] flying: has joined #ruby
[07:36:42] roshanavand: has joined #ruby
[07:37:54] tsul: has joined #ruby
[07:42:01] ur5us: has joined #ruby
[07:48:42] mark_66: has joined #ruby
[07:51:29] MarkBilk_: has joined #ruby
[08:09:23] TheHodge: has joined #ruby
[08:12:12] MarkBilk: has joined #ruby
[08:14:27] sonOfRa: has joined #ruby
[08:15:42] mim1k: has joined #ruby
[08:20:30] nobitanobi: has joined #ruby
[08:20:56] al2o3-cr: has joined #ruby
[08:21:55] Polysics: has joined #ruby
[08:25:23] rohitpaulk: has joined #ruby
[08:25:33] nobitano_: has joined #ruby
[08:32:05] dionysus69: has joined #ruby
[08:36:05] cfec0b8d: has joined #ruby
[08:44:10] tomphp: has joined #ruby
[08:49:30] andikr: has joined #ruby
[08:50:17] tomphp: has joined #ruby
[08:50:59] Emmanuel_Chanel: has joined #ruby
[08:56:23] gregf_: has joined #ruby
[08:57:15] tomphp: has joined #ruby
[08:58:44] workmad3: has joined #ruby
[09:02:21] lxsameer: has joined #ruby
[09:03:16] nowhereman: has joined #ruby
[09:07:26] jusa: has joined #ruby
[09:09:20] Pumukel: has joined #ruby
[09:11:06] jgnagy: has joined #ruby
[09:11:32] vdl: has joined #ruby
[09:12:16] BSaboia: has joined #ruby
[09:12:27] nowhere_man: has joined #ruby
[09:18:39] Mortomes|Work_: has joined #ruby
[09:22:56] vali: has joined #ruby
[09:26:33] Shashikant86: has joined #ruby
[09:26:36] anisha: has joined #ruby
[09:29:04] helpa: has joined #ruby
[09:30:12] vondruch_: has joined #ruby
[09:30:27] jaruga_________: has joined #ruby
[09:30:47] edgr: has joined #ruby
[09:31:20] ikopico: has joined #ruby
[09:31:41] Archrover: has joined #ruby
[09:32:23] urbanslug: has joined #ruby
[09:32:28] bokayio: has joined #ruby
[09:32:30] ur5us: has joined #ruby
[09:32:39] duracrisis: has joined #ruby
[09:34:06] sysanthrope: has joined #ruby
[09:34:21] nobitanobi: has joined #ruby
[09:37:54] acemo_: has joined #ruby
[09:38:44] tomphp: has joined #ruby
[09:39:00] harfangk: has joined #ruby
[09:40:40] tomphp: has joined #ruby
[09:41:22] marr: has joined #ruby
[09:47:53] andikr: has joined #ruby
[09:49:04] dyjakan: has joined #ruby
[09:49:04] badeball: has joined #ruby
[09:49:05] syndikate: has joined #ruby
[09:49:08] jhass: has joined #ruby
[09:49:09] csaunders: has joined #ruby
[09:49:09] Didac: has joined #ruby
[09:49:09] Tralin: has joined #ruby
[09:49:10] bhaak: has joined #ruby
[09:49:10] wopi: has joined #ruby
[09:49:11] uranellus: has joined #ruby
[09:49:11] uranellus: has joined #ruby
[09:49:11] ablackack: has joined #ruby
[09:49:12] ByronJohnson: has joined #ruby
[09:49:14] kiltzman: has joined #ruby
[09:49:14] ddrmanxbxfr: has joined #ruby
[09:49:17] iNs: has joined #ruby
[09:49:22] yorickpeterse: has joined #ruby
[09:49:25] Sou|cutter: has joined #ruby
[09:49:33] shortdudey123: has joined #ruby
[09:49:34] lpaste: has joined #ruby
[09:49:35] Drakevr: has joined #ruby
[09:50:37] Karunamon: has joined #ruby
[09:51:03] ntt: has joined #ruby
[09:53:59] bokayio: has joined #ruby
[09:54:15] gf3: has joined #ruby
[09:54:19] ferr1: has joined #ruby
[09:55:18] kke: how would i make my own Foo("123") coercer thing, like Integer("123"), Array(foo), etc?
[09:55:30] dionysus69: btw I made a script to auto upload youtube videos based on what data is in google sheets https://github.com/webzorg/google-api-automation, maybe someone may use it as a template :)
[09:55:57] canton7: kke, 'def Foo(input) ...'
[09:56:25] kke: monkeypatching Object i guess
[09:57:34] ljarvis: you don't need to monkeypatch Object
[09:59:26] kke: or Kernel. isn't that what you are monkeypatching if you run `def foo` from main?
[10:00:25] kke: >> def foo; puts "bar"; end; Kernel.method(:foo).call
[10:00:30] zenspider: you're conflating "monkeypatching"
[10:04:46] kke: looks like Array() String() etc are defined as methods in Kernel https://ruby-doc.org/core-2.4.1/Kernel.html#method-i-Array
[10:06:03] ljarvis: sure, you can add it to Kernel. You could also just drop it into the top level of your code
[10:07:06] mtkd: has joined #ruby
[10:07:25] ljarvis: (which is kind of the same thing)
[10:07:43] kke: unless you're `load`ing the file
[10:07:51] kke: from some strange context
[10:08:09] kke: i think
[10:13:31] rt: has joined #ruby
[10:13:31] Emmanuel_Chanel: has joined #ruby
[10:13:32] roshanavand: has joined #ruby
[10:13:32] flying: has joined #ruby
[10:13:32] Authenticator: has joined #ruby
[10:13:32] millerti: has joined #ruby
[10:13:32] my123: has joined #ruby
[10:13:32] romain_t: has joined #ruby
[10:13:32] dhollinger: has joined #ruby
[10:13:32] Jn_Kell: has joined #ruby
[10:13:32] aspiers: has joined #ruby
[10:13:32] dn`: has joined #ruby
[10:13:32] am55: has joined #ruby
[10:13:32] jidar: has joined #ruby
[10:13:32] lagweezle_away: has joined #ruby
[10:13:32] irick: has joined #ruby
[10:13:32] eam: has joined #ruby
[10:13:32] sjums: has joined #ruby
[10:13:32] segy: has joined #ruby
[10:13:32] camilasan: has joined #ruby
[10:13:32] giraffe: has joined #ruby
[10:13:32] ltp: has joined #ruby
[10:13:33] JDeen: has joined #ruby
[10:13:33] noctux: has joined #ruby
[10:13:33] avelldiroll: has joined #ruby
[10:13:33] cbrad: has joined #ruby
[10:13:33] Prira_: has joined #ruby
[10:13:33] nemesit|znc: has joined #ruby
[10:13:33] veloutin: has joined #ruby
[10:13:33] marcellus: has joined #ruby
[10:13:33] alnewkir1: has joined #ruby
[10:13:33] genta: has joined #ruby
[10:13:33] thejoecarroll_: has joined #ruby
[10:14:23] segy: has joined #ruby
[10:14:32] nemesit|znc: has joined #ruby
[10:14:47] flying: has joined #ruby
[10:14:52] thejoecarroll: has joined #ruby
[10:14:55] Mortomes|Work_: has joined #ruby
[10:14:55] vondruch_: has joined #ruby
[10:14:55] jaruga_________: has joined #ruby
[10:14:55] acemo_: has joined #ruby
[10:15:07] nemesit|znc: has joined #ruby
[10:15:39] t-recx: has joined #ruby
[10:16:52] rt: has joined #ruby
[10:18:31] bokayio: has joined #ruby
[10:18:34] syndikate: has joined #ruby
[10:18:37] SirFunk: has joined #ruby
[10:18:50] Radar: has joined #ruby
[10:18:51] rgr: has joined #ruby
[10:19:07] leonthemisfit: has joined #ruby
[10:19:08] leonthemisfit: has joined #ruby
[10:22:32] nowhereman: has joined #ruby
[10:25:12] mathys: has joined #ruby
[10:27:16] roshanavand: has left #ruby: ()
[10:27:17] GodFather: has joined #ruby
[10:28:59] tomphp: has joined #ruby
[10:30:43] pandaant: has joined #ruby
[10:38:40] olivier__: has joined #ruby
[10:45:19] charliesome: has joined #ruby
[10:46:16] roshanavand: has joined #ruby
[10:52:56] tomphp: has joined #ruby
[10:54:54] anisha: has joined #ruby
[11:04:59] opencw: has joined #ruby
[11:05:56] jrafanie: has joined #ruby
[11:08:12] jusa: has joined #ruby
[11:10:48] gil_: has joined #ruby
[11:11:06] gil_: has joined #ruby
[11:11:51] tomphp: has joined #ruby
[11:20:45] alveric4: has joined #ruby
[11:25:07] ChewCraft: has joined #ruby
[11:35:43] HoierM: has joined #ruby
[11:37:06] jokester: has joined #ruby
[11:37:17] ldnunes: has joined #ruby
[11:37:45] djbkd: has joined #ruby
[11:38:48] A124: has joined #ruby
[11:47:36] yogg-saron: has joined #ruby
[11:48:38] jane_booty_doe: has joined #ruby
[11:49:49] im0nde: has joined #ruby
[11:52:35] im0nde: has joined #ruby
[11:58:20] burgestrand: has joined #ruby
[12:00:50] jane_booty_doe: has joined #ruby
[12:01:19] bkxd: has joined #ruby
[12:02:16] jbdoe: has joined #ruby
[12:02:43] olivier__: has joined #ruby
[12:03:14] olivier__: has joined #ruby
[12:06:54] olivier__: has joined #ruby
[12:08:27] synthroid: has joined #ruby
[12:10:14] belmoussaoui: has joined #ruby
[12:12:00] xall: has joined #ruby
[12:14:28] belmoussaoui__: has joined #ruby
[12:19:51] sepp2k: has joined #ruby
[12:20:48] sepp2k: has joined #ruby
[12:21:55] pupsicle: has joined #ruby
[12:22:11] dminuoso: asm>> Array(1..2)
[12:22:12] ruby[bot]: dminuoso: I have disassembled your code, the result is at https://eval.in/807655
[12:22:14] dminuoso: asm>> Foo(1..2)
[12:22:15] ruby[bot]: dminuoso: I have disassembled your code, the result is at https://eval.in/807656
[12:23:04] dminuoso: kke: If you use load you have already subscribed to the special semantic it incurs.
[12:23:35] Guest6988: has joined #ruby
[12:23:51] mostlybadfly: has joined #ruby
[12:25:12] jenrzzz: has joined #ruby
[12:25:12] jenrzzz: has joined #ruby
[12:25:32] hashrocket: has joined #ruby
[12:30:24] nobitanobi: has joined #ruby
[12:30:42] djbkd: has joined #ruby
[12:31:10] konsolebox: has joined #ruby
[12:31:45] teclator: has joined #ruby
[12:31:47] djbkd: has joined #ruby
[12:32:47] rgr: has joined #ruby
[12:34:58] PatrikasZvaigzde: has joined #ruby
[12:39:44] shinnya: has joined #ruby
[12:42:36] jaruga_________: has joined #ruby
[12:45:28] tomphp: has joined #ruby
[12:45:33] mim1k: has joined #ruby
[12:49:41] roamingdog: has joined #ruby
[12:53:41] bruce_lee: has joined #ruby
[12:53:42] bruce_lee: has joined #ruby
[12:56:19] yogg-saron: has joined #ruby
[12:57:38] jane_booty_doe: has joined #ruby
[12:58:14] haylon: has joined #ruby
[12:59:24] opencw: has joined #ruby
[13:00:17] stupidsenpai: has joined #ruby
[13:00:39] jgt: has joined #ruby
[13:03:40] kthibodeaux: has joined #ruby
[13:04:57] SaschaVoid: has joined #ruby
[13:07:06] apparition: has joined #ruby
[13:08:15] pandaant: has joined #ruby
[13:09:05] jusa: has joined #ruby
[13:13:24] quazimodo: has joined #ruby
[13:15:52] kke: yes. just hypothesising.
[13:16:45] sysanthrope: has joined #ruby
[13:19:14] gnufied: has joined #ruby
[13:21:34] yottanami: has joined #ruby
[13:22:04] yottanami: How can I write this code `total = 0;@products.each{|product| total += product.price}` using reduce?
[13:22:08] dminuoso: kke: Though no, it does not execute like you suggested.
[13:22:34] apeiros: kke: proper way to define Foo() is `module Kernel; module_function def Foo(…) … end; end`
[13:22:38] dminuoso: kke: Basically the main difference between the two is that require will not require the same file twice, whereas load will do it again. And load has a second argument (which is not very useful)
[13:23:00] mim1k: has joined #ruby
[13:23:09] apeiros: yottanami: @products.inject(0) { |sum, product| sum + product.price }
[13:23:26] dminuoso: yottanami: @products.map(&:price).inject(&:+)
[13:23:35] apeiros: dminuoso: don't forget about suffix requirement
[13:23:47] dminuoso: apeiros: mine is shorter! and slower!
[13:23:58] apeiros: dminuoso: shame on you for using &:+ instead of :+, also it's not equivalent without 0 as initial value
[13:24:14] dminuoso: apeiros: Oh. I keep forgetting which stupid enumerable methods support symbols and which dont.
[13:24:27] apeiros: basically inject. only. nothing else.
[13:24:28] dminuoso: Or idk. You are right.
[13:24:36] ur5us: has joined #ruby
[13:24:44] apeiros: I still wish others would too
[13:24:48] dminuoso: @products.map(:price).inject(:+) || 0
[13:24:48] apeiros: like map, select, reject
[13:24:50] dminuoso: apeiros: ^- ?
[13:25:07] cjohnson: Would anybody mind taking a quick look at my exercise and tell me things I could have done better? This is beginner stuff so don't go too crazy but if I did any obviously silly things let me know: https://gist.github.com/chrisjohnson/af563f8c350e7e863c07b730812fee4a
[13:25:11] herwin: @products.map(:price).sum
[13:25:14] apeiros: yes. I'd love it if that'd work as intended. alas it doesn't.
[13:25:14] cjohnson: http://exercism.io/exercises/ruby/raindrops/readme the exercise
[13:25:17] dminuoso: herwin wins.
[13:25:42] herwin: only when we're using ruby 2.4 or higher ;)
[13:25:52] apeiros: herwin loses because it's not working
[13:26:09] apeiros: even in 2.4, you need &:price
[13:26:20] apeiros: but yes, .sum++ :)
[13:26:27] cjohnson: Already caught something, I should have just used a constant for factor_words
[13:26:28] dminuoso: We all fail so hard at this.
[13:26:40] apeiros: but loses again because that was not the question. the question specifically asked for inject/reduce :)
[13:26:47] dminuoso: Any way we can bikeshed yottanami's problem any further?
[13:27:09] apeiros: dminuoso: assume @products is an AR Relation
[13:27:11] apeiros: there you go
[13:27:16] apeiros: yottanami: is it? :D
[13:27:27] dminuoso: apeiros: @products.sum(:price)
[13:27:31] dminuoso: or something like that.
[13:27:36] dminuoso: I dont do AR silly stuff.
[13:27:40] dminuoso: Im a manly SQL man.
[13:27:43] apeiros: dminuoso: indeed. || 0 for equivalency
[13:27:58] dminuoso: Oh that reminds me
[13:28:01] apeiros: yeah, AR's abstraction is too leaky.
[13:28:02] yottanami: dminuoso, It is not Active Record it is a simple object
[13:28:12] dminuoso: I should submit a merge request for my where(foo: "") fix for the oracle enhanced adapter, apeiros.
[13:28:19] dminuoso: because seriously that shit is annoying.
[13:28:30] cjohnson: updated to use a constant for FACTOR_WORDS
[13:28:34] apeiros: hm, which way would you want that to work?
[13:28:44] kke: apeiros: looks clean and nice.
[13:28:51] dminuoso: apeiros: consider that you might have where(foo: bar) ;-)
[13:28:54] apeiros: create_empty_blob() or whatever the function was to create a true empty clob?
[13:29:17] bkxd: has joined #ruby
[13:29:19] apeiros: dminuoso: well, afaik that works correctly, regardless of whether it's nil/"", no?
[13:29:20] dminuoso: apeiros: You taught me that. I surprised the hell out of our oracle expert with that.
[13:29:42] dminuoso: apeiros: No. It emits a stupid where foo = '' clause
[13:29:52] apeiros: it's too hot here!
[13:29:57] apeiros: I lose access to basic knowledge!
[13:29:59] dminuoso: That high up in the alps?
[13:30:08] apeiros: I'm at only ~400müm
[13:30:11] __Yiota: has joined #ruby
[13:30:20] apeiros: what's müm in english? masl?
[13:30:23] dminuoso: Oh really, I didn't know that
[13:30:39] apeiros: (meters above sea level)
[13:30:44] dminuoso: apeiros: NHN
[13:30:56] dminuoso: Is international even
[13:31:28] apeiros: lol, even though it stands for Normalhöhennull?
[13:31:52] dminuoso: Yeah. meters above NHN.
[13:31:53] apeiros: seems like.
[13:32:00] apeiros: so 500NHN?
[13:32:11] apeiros: or 500man? (500 meters above NHN)?
[13:32:17] apeiros: this stuff is silly
[13:32:29] apeiros: and it's still too effing hot
[13:32:40] apeiros: or fracking hot, if you're a battlestarist
[13:33:00] dminuoso: Fracking hot is that chick just passed by on the street.
[13:33:03] herwin: apeiros: you probably have to convert the meters to feet as well
[13:33:22] dminuoso: apeiros: She could have been number six.
[13:34:02] apeiros: dminuoso: I'm more of a treckie, so… a 7of9?
[13:34:26] dminuoso: Very much so.
[13:34:36] dminuoso: number six is seven of nine without implants.
[13:34:50] dminuoso: Since it's basically taking a seven and removing parts.
[13:34:52] dminuoso: So you end up with six.
[13:35:04] dminuoso: Does that make any sense?
[13:35:13] apeiros: the mathematical relation between ST:VOY and BSG
[13:35:19] apeiros: we're very OT btw.
[13:35:40] dminuoso: def we_can_express_this; in_ruby(:code); too(); end
[13:35:54] dminuoso: %[no longer offtopic now, is it?]
[13:36:09] apeiros: def I(think: "this"); qualifies.as(:cheating); end
[13:36:52] dminuoso: apeiros: In Germany it's `m ü NHN'
[13:37:17] apeiros: not enough acronym inception
[13:37:42] dminuoso: That's because inception wasnt made when they came up with that.
[13:37:57] dminuoso: Pray that SI doesnt get wind of this.
[13:38:00] ltem: has joined #ruby
[13:38:29] nobodyzxc: has joined #ruby
[13:38:44] apeiros: GNU existed before too
[13:38:55] apeiros: and that's even infinite recursive acronym inception
[13:39:01] dminuoso: Im not sure about that.
[13:39:10] cjohnson: So I understand that :foo is a Symbol for 'foo', so can somebody explain to me what :+ here is doing? (5..10).reduce(:+)
[13:39:12] dminuoso: I have expanded GNU quite deeply, but Im not convinced that its truly recursive.
[13:39:19] cjohnson: from the ruby docs on Enumerable#reduce
[13:39:26] apeiros: cjohnson: :foo is not a symbol for "foo"
[13:39:51] cjohnson: "foo" is the string representation of the symbol :foo
[13:39:52] dminuoso: cjohnson: symbols are just a very fast way method of conveying information.
[13:39:53] apeiros: :foo is a symbol. its "value" can be represented by the string "foo". though it's actual value is actually a number.
[13:39:56] dminuoso: cjohnson: No it is not.
[13:40:02] dminuoso: cjohnson: symbols are just numbers
[13:40:06] dminuoso: that happen to have a string representation.
[13:40:19] cjohnson: Right, and in the case of :foo, is the string representation not "foo"?
[13:40:30] dminuoso: cjohnson: The reason has to do with the fact that equality checks with numbers are much much faster than equality checks with strings.
[13:40:40] apeiros: anyway, to answer your question
[13:40:44] dminuoso: cjohnson: no.
[13:40:51] apeiros: the :+ tells inject that it should use the method +
[13:40:53] dminuoso: cjohnson: the string representation *IS* :foo
[13:40:59] dminuoso: >> :foo.to_i
[13:41:01] ruby[bot]: dminuoso: # => undefined method `to_i' for :foo:Symbol ...check link for more (https://eval.in/807766)
[13:41:02] apeiros: and the internal representation of method names are … tadaaa… symbols
[13:41:05] cjohnson: >> :foo.to_s
[13:41:06] ruby[bot]: cjohnson: # => "foo" (https://eval.in/807767)
[13:41:07] dminuoso: >> :foo.internal
[13:41:08] ruby[bot]: dminuoso: # => undefined method `internal' for :foo:Symbol ...check link for more (https://eval.in/807768)
[13:41:16] cjohnson: looks like "foo" is the string representation of :foo ??
[13:41:20] dminuoso: >> :foo.intern
[13:41:22] ruby[bot]: dminuoso: # => :foo (https://eval.in/807769)
[13:41:25] dminuoso: cjohnson: no thats an actual conversion.
[13:41:42] cjohnson: I understand that the string is not the unique ID I'm just saying
[13:41:48] ResidentBiscuit: has joined #ruby
[13:42:10] cjohnson: apeiros: Ok that makes sense
[13:42:13] ResidentBiscuit: has joined #ruby
[13:42:13] apeiros: interesting. seems current ruby no longer lets you access the numeric value.
[13:42:16] dminuoso: >> :foo.object_id
[13:42:17] ruby[bot]: dminuoso: # => 450738 (https://eval.in/807770)
[13:42:18] dminuoso: cjohnson: ^- there.
[13:42:23] cjohnson: Do all methods have symbols?
[13:42:27] apeiros: cjohnson: no
[13:42:28] dminuoso: cjohnson: Yes.
[13:42:37] apeiros: cjohnson: misunderstanding
[13:42:50] apeiros: all identifiable things in ruby have their identification as symbols
[13:43:01] apeiros: so "yes, all methods have symbols" if you accept bad wording :-p
[13:43:13] cjohnson: I'm newb, accept my bad wording for now please lol
[13:43:17] apeiros: proper: "yes, all methods are identified by a symbol"
[13:43:38] cjohnson: so in JS you can pass functions around as first class values. In ruby it seems like if you want to pass a method you want to pass its symbol
[13:43:47] dminuoso: cjohnson: It depends.
[13:43:53] dminuoso: cjohnson: You can also pass methods as first class values
[13:43:58] dminuoso: it just takes a little extra effort to do so.
[13:43:59] elomatreb: You can detach methods, but you need to attach them again if you want to call them
[13:44:04] cjohnson: dminuoso: can you give an example?
[13:44:12] apeiros: it's gotten a bit trickier to prove that since ruby seems to create symbols more eagerly. but back in the days you could prove it by: `before = Symbol.all_symbols.dup; def foobarbaz; end; p(Symbol.all_symbols - before)`
[13:44:18] apeiros: it'd print "[:foobarbaz]"
[13:44:23] dminuoso: >> a = "foo".method(:length); p a
[13:44:24] ruby[bot]: dminuoso: # => #<Method: String#length> ...check link for more (https://eval.in/807771)
[13:44:26] dminuoso: cjohnson: ^-
[13:44:37] dminuoso: cjohnson: but yeah, you'd usually go the symbol way
[13:44:41] apeiros: elomatreb: you don't have to detach
[13:44:53] apeiros: elomatreb: .instance_method detaches, .method doesn't
[13:44:57] dminuoso: cjohnson: the interesting thing is, when you do "foo".length what actually happens internally is "foo".send(:length)
[13:45:03] kubunto: has joined #ruby
[13:45:05] dminuoso: which is why using symbols is about as good.
[13:45:22] cjohnson: gotchya, that makes sense. so everything in ruby is implemented as a method basically?
[13:45:25] cjohnson: as far as operations
[13:45:29] dminuoso: cjohnson: No.
[13:45:37] apeiros: cjohnson: there are some syntax operations. but they are rare.
[13:45:41] dminuoso: cjohnson: There's some things that are optimized away.
[13:45:43] apeiros: defined?, &&, || and a couple of others
[13:45:52] cjohnson: oh yeah good call
[13:45:57] apeiros: those are probably the most common syntax based operations
[13:45:58] cjohnson: those make sense
[13:46:00] matthewd: But yes, most operators are methods
[13:46:17] apeiros: stuff like +, -, ^, =~, [], []= etc. are despite their look actually methods
[13:46:21] dminuoso: cjohnson: for example: 1+2 is not a method
[13:46:29] ruby[bot]: dminuoso: I have disassembled your code, the result is at https://eval.in/807774
[13:46:33] HoierM: has joined #ruby
[13:46:37] cjohnson: Isn't that slow?
[13:46:38] dminuoso: cjohnson: it's built as an immediate optimized vm instruction.
[13:46:53] apeiros: e.g. `foo[123, 45] = 67` is actually `foo.[]=(123,45,67)`, or `foo.send(:[]=, 123,45,67)`
[13:47:00] dminuoso: cjohnson: And yes, the worst part because methods can be monkey patched by anyone at any time, it leads to horribile performance.
[13:47:51] apeiros: dminuoso: makes me wonder whether ruby 3 will finally have that deoptimization thingy in it. they wanted to speed up arithmetic operations for inferred types and only deoptimize in case any of those get overridden (which happens almost never)
[13:47:52] __Yiota: has joined #ruby
[13:47:59] matthewd: dminuoso: Except yes it is a method
[13:48:06] cjohnson: So what is the general stance? Do seasoned rubyists tend to scoff at a lot of metaprogramming because it leads to bad performance?
[13:48:13] dminuoso: matthewd: Oh. oh. Yes.
[13:48:15] cjohnson: or are there good ways to get good performance without giving it all up
[13:48:16] dminuoso: You are right.
[13:48:28] matthewd: The fact the implementation has a shortcut for the default behaviour doesn't change that.
[13:48:32] dminuoso: cjohnson: No, the performance penalty has been incurred when you use Ruby.
[13:48:48] apeiros: and that penalty isn't as bad anymore as it used to be
[13:48:59] dminuoso: cjohnson: The mere fact that it *is* possible prevents Ruby from doing trivial optimizations.
[13:49:12] cjohnson: ok that makes sense
[13:49:13] apeiros: the general consensus is that in most code it doesn't matter and that ruby saves enough time to rewrite sensitive stuff in native code if necessary.
[13:49:35] apeiros: and in most cases it becomes evident that it isn't actually necessary
[13:49:42] apeiros: so you just get the saved time ;-)
[13:49:53] cjohnson: Yeah I get that, coming from JS and PHP
[13:49:57] dminuoso: cjohnson: Though if you look at chrisseaton's (et al) truffle/graal you can actually see amazing JIT behavior that can tackle these dynamic portions
[13:50:04] dminuoso: and bring Ruby in line with Java in terms of performance
[13:50:05] cjohnson: spent a lot of time telling C++ devs to chill out about performance
[13:50:29] dminuoso: cjohnson: So it can be optimized. But MRI doesn't do much (yet)
[13:50:51] apeiros: bottom line: ruby is not the best choice for everything. now replace "ruby" with anything.
[13:51:23] dminuoso: cjohnson: In fact Ruby only optimizes the most trivial cases during compile time, and then tries to do the rest with heavy caching and cache invalidation strategies left and right.
[13:51:47] elomatreb: No, Javascript is obviously the perfect language and is probably what the universe is implemented in
[13:51:52] cjohnson: Seems like that leads to limited static analysis tooling
[13:52:00] dminuoso: cjohnson: Indeed.
[13:52:04] cjohnson: can you lint ruby very well?
[13:52:16] elomatreb: It does, you need to write extensive comments for documentation
[13:52:17] dminuoso: Only for style mostly.
[13:52:27] cjohnson: elomatreb: lol yeah so then the answer is no
[13:52:40] apeiros: elomatreb: you surely meant lisp
[13:52:50] dminuoso: cjohnson: But the dynamic nature makes static analysis completely impossible. something like flowtype is not possible in pure ruby
[13:52:54] dminuoso: cjohnson: However there's Crystal.
[13:53:00] elomatreb: cjohnson: I was replying to "Seems like that leads to limited static analysis tooling" ;)
[13:53:28] cjohnson: Fair. Either way, if it relies on commenting, that means it's pretty limited imo
[13:53:34] cjohnson: most of those tools are there to catch things I didn't think of
[13:53:52] dminuoso: cjohnson: The fact that you can brutally pry into ObjectSpace means you can globally fuck around with any object
[13:53:53] dminuoso: from anywhere.
[13:54:02] dminuoso: Which makes it impossible for any static tool to reason about anything.
[13:54:46] cjohnson: So there's no such thing as a sandboxed namespace that is safe from being touched by other code?
[13:54:50] elomatreb: The flipside of the Rust strategy of having programmers fight the compiler to get the program running
[13:55:03] matthewd: cjohnson: Correct
[13:56:06] dminuoso: elomatreb: Im not convinced. The program compilers if your semantics are right, and if the compiler emits errors it means your program is wrong.
[13:56:11] beccamorgan: has joined #ruby
[13:56:12] dminuoso: *the compiler errors..
[13:56:26] dminuoso: err *the program compiles..
[13:56:35] dminuoso: too hot. way too hot.
[13:57:16] elomatreb: Of course, but it makes translating the abstract concept of what you want to implement into code which the compiler then can translate harder
[13:57:40] dminuoso: elomatreb: In JS I find myself spending all that time "saved fighting the compiler" writing tests and flowtype definitions to ensure that proper semantics are preserved. So basically voiding all that effort saved. :P
[13:57:51] matthewd: dminuoso: if the compiler emits errors it means the compiler can't prove that your program is right
[13:58:02] dminuoso: matthewd: No, but it can prove its wrong.
[13:58:13] dminuoso: Ruby doesn't do either.
[13:58:27] dminuoso: Or rather JS since that was the basis of this discussion.
[13:58:48] railswebdev: has joined #ruby
[13:59:10] tvw: has joined #ruby
[13:59:35] dminuoso: matthewd: Mind my asking since I was curious anyway. Do you contribute to Rails for a living?
[14:00:07] chouhoul_: has joined #ruby
[14:02:09] matthewd: Not particularly. Mostly free time, but if my employer has a specific need, then I'm obviously well placed to help stuff happen.
[14:09:27] bkxd_: has joined #ruby
[14:15:03] tomphp: has joined #ruby
[14:17:07] eblip: has joined #ruby
[14:22:21] A124: has joined #ruby
[14:25:04] oleo: has joined #ruby
[14:25:28] charliesome: has joined #ruby
[14:26:36] cjohnson: It seems like blocks get some sort of special treatment when being passed into functions. For example, to pass a block to Enumerable#reduce, you can just pass it like foo.reduce { |n| ... }
[14:26:45] jrafanie: has joined #ruby
[14:27:00] cjohnson: But if you want to pass an initial value, it needs to be in a sorta seperate set of arguments, like: foo.reduce(0) { |n| ... }
[14:27:20] cjohnson: why is that? where can I read more about that behavior? Do methods get a special "block argument" space that is separate from normal args?
[14:27:41] matthewd: cjohnson: Yes, the block parameter is a syntactically separate thing
[14:27:50] cjohnson: ok so it's kinda like `this` in JS
[14:27:56] cjohnson: it's an argument, but it doesn't sit in the normal args list
[14:28:09] cjohnson: Are you limited to one block?
[14:28:10] apeiros: you can have it in the arg list too
[14:28:14] apeiros: yes, one block only
[14:28:38] apeiros: re in arg list: add_one = ->(n) { n + 1 }; [1,2,3].map(&add_one)
[14:28:39] cjohnson: How do you access teh block? does it do anythin magic or is it just an argument that the mehtod can use how it sees fit?
[14:28:48] LastWhisper____: has joined #ruby
[14:29:09] apeiros: you can tell ruby to create an object representation of it by defining your method with a &arg: `def foo(&arg); …`
[14:29:20] apeiros: the variable `arg` will then contain the block
[14:29:24] matthewd: cjohnson: `yield` and `block_given?` built-ins, or &arg ^^
[14:29:31] cjohnson: interesting
[14:29:31] apeiros: if you don't need an object ^
[14:29:45] cjohnson: Are arguments optional? What happens if you omit a block in the def foo(&arg) ?
[14:30:03] GodFather: has joined #ruby
[14:30:04] apeiros: also `Proc.new` (without a block) will create a proc from the block (that's arcane btw., not many ruby coders will understand)
[14:30:05] matthewd: Block arguments are optional; others are required unless they have a default
[14:30:43] apeiros: I'd amend this to: blocks are *always* optional. it'll only ever raise if it tries to actually access it.
[14:30:54] apeiros: also you can pass a block to methods which don't make use of it:
[14:31:02] apeiros: >> puts "hi" do "what?" end
[14:31:03] ruby[bot]: apeiros: # => hi ...check link for more (https://eval.in/807865)
[14:31:13] apeiros: they'll simply ignore the block.
[14:31:25] apeiros: (NB: I don't exactly like that behavior)
[14:31:53] mikecmpbll: has joined #ruby
[14:33:32] cdg: has joined #ruby
[14:34:07] patarr: has joined #ruby
[14:34:40] cdg: has joined #ruby
[14:37:18] __Yiota: has joined #ruby
[14:37:49] cjohnson: interesting
[14:38:51] apeiros: also note that `super`'s behavior wrt blocks and arguments is super unobvious
[14:39:46] apeiros: `super` passes on all args passed to the method, `super()` will pass zero arguments, but will still pass on a block passed to the current method, `super(&nil)` passes no arguments and suppresses passing the block
[14:40:08] hobodave: has joined #ruby
[14:40:23] apeiros: note that in `def foo(a,b); a = 2; super; end; foo(5, 6)` will invoke the super method with the arguments (2, 6)
[14:40:40] belmoussaoui: has joined #ruby
[14:45:14] cjohnson: oh that looks lovely lol
[14:45:47] cjohnson: Thanks apeiros that is a fantastic little explanation of various gotchyas
[14:46:48] tomphp: has joined #ruby
[14:46:53] cjohnson: So def foo(&block, a, b) will I call that as foo(1, 2) { |n| ... } ?
[14:47:05] cjohnson: same q with foo(a, b, &block)
[14:47:06] meshsmith: has joined #ruby
[14:47:26] matthewd: &block has to come last, but yes
[14:47:27] cjohnson: does it just sort of pluck the &block arg out of the list? or do I need it in a certain place
[14:47:36] cjohnson: makes sense
[14:47:56] cjohnson: Ok I think this is my last question for at least 10 minutes: Can you use both &block arg and the yield operator?
[14:48:22] antgel: has joined #ruby
[14:48:29] matthewd: Yes (and they'll both use the same/only block)
[14:48:30] cjohnson: >> def foo(&block); block; yield; block; end; foo { puts 'block' }
[14:48:32] ruby[bot]: cjohnson: # => block ...check link for more (https://eval.in/807898)
[14:49:14] dn`: has joined #ruby
[14:49:27] cjohnson: Why only 1 "block" here?
[14:49:57] apeiros: because reasons
[14:50:03] apeiros: design decision I guess
[14:50:11] havenwood: cjohnson: The return value is the one block. If you want those blocks to call: block.call
[14:50:18] apeiros: you can always pass any number of lambdas or procs, though
[14:50:42] cjohnson: Oh does puts not work in the bot? maybe that was my issue?
[14:50:58] apeiros: click the link
[14:51:04] cjohnson: I get why the final block was returned after havenwood's comment
[14:51:12] cjohnson: I did but I don't see "block" printed 3 times
[14:51:30] cjohnson: given the return
[14:51:31] apeiros: I misunderstood your question btw., I thought "why only 1 block" as "why only 1 block argument"
[14:51:45] cjohnson: >> def foo(&block); block; yield; block; end; foo { puts 'I am here' }
[14:51:46] ruby[bot]: cjohnson: # => I am here ...check link for more (https://eval.in/807899)
[14:51:52] apeiros: as havenwood said, block.call
[14:52:07] cjohnson: Oh so you can't use a block like a method
[14:52:14] apeiros: it isn't a method :)
[14:52:18] apeiros: it's an object
[14:52:25] apeiros: or rather, "block" is a local variable
[14:52:32] apeiros: referencing to a reified block
[14:53:10] mtkd: has joined #ruby
[14:53:21] cjohnson: >> def foo(&block); block.call; yield; block.call; 'my return'; end; foo { puts 'I am here' }
[14:53:22] ruby[bot]: cjohnson: # => I am here ...check link for more (https://eval.in/807900)
[14:53:48] cjohnson: Nice! https://media.giphy.com/media/rl0FOxdz7CcxO/giphy.gif
[14:54:06] cjohnson: Thanks much everybody for helping me understand this stuff
[14:54:42] cjohnson: Is there any magic to `yield`? Or does it basically just do block.call
[14:54:51] apeiros: next level: figure out how scoping works related to `next`, `break`, `return`
[14:54:59] cjohnson: Cool, I will do some research on that stuff
[14:55:01] apeiros: it does block.call, with less effort
[14:55:12] cdg_: has joined #ruby
[14:55:13] apeiros: converting between object and object-less block costs a bit
[14:55:38] cjohnson: Ok so using yield over using a named block arg seems like it would be the more common usage
[14:55:42] cjohnson: especially given the limit to 1 block
[14:55:46] apeiros: performance considerations: `def foo; yield; end` is faster than `def foo(&block); block.call; end`
[14:56:14] apeiros: but: `def foo; @data.each do |*args| yield(*args) end; end` is *slower* than `def foo(&block); @data.each(&block); end`
[14:56:23] aurelien: has joined #ruby
[14:56:31] apeiros: i.e. passing on a block which is invoked multiple times -> use &block
[14:56:38] apeiros: invoke a block directly -> use yield
[14:56:41] cjohnson: makes sense
[14:56:57] cjohnson: so Enumerable#reduce probably uses the named version (if you were to write the method in ruby)
[14:57:06] cjohnson: and other such enumerable stuff
[14:57:13] apeiros: and obviously: if you want to invoke the block at another time (aka "later") - use block
[14:57:47] apeiros: since it adds its own stuff in each iteration, I'd probably write it using yield
[14:57:56] apeiros: it's not a blanket delegation
[14:58:08] SuperLag: has joined #ruby
[15:02:23] CacoS: has joined #ruby
[15:04:29] rippa: has joined #ruby
[15:05:54] jrafanie: has joined #ruby
[15:07:00] __Yiota: has joined #ruby
[15:07:43] roychri: has joined #ruby
[15:08:40] cjohnson: https://www.sitepoint.com/understanding-scope-in-ruby/ cool, this all makes sense to me. It seems pretty similar to JS in respect to scoping
[15:09:19] jgnagy: has joined #ruby
[15:15:48] mikecmpbll: has joined #ruby
[15:15:55] cschneid_: has joined #ruby
[15:19:18] TomyLobo: has joined #ruby
[15:21:15] kegster: has joined #ruby
[15:21:26] olivier__: has joined #ruby
[15:21:55] u0_a190: has joined #ruby
[15:21:56] cjohnson: Ok so @@ and @ are sorta like "static" variables that exist at the class level, and the difference seems to be in inheritance
[15:22:18] cjohnson: >> class Foo; attr_accessor :thing; thing = 'my thing'; end; Foo.new.thing
[15:22:19] ruby[bot]: cjohnson: # => nil (https://eval.in/807906)
[15:22:44] cjohnson: Am I misunderstanding how to use thing = 'my thing' here? I found a similar example in that sitepoint article
[15:22:54] cjohnson: My guess is probably that thing = 'my thing' needs to go in initialize
[15:22:58] matthewd: cjohnson: That's setting a local variable called 'thing'
[15:23:05] cjohnson: local to the instance?
[15:23:23] matthewd: Local to the scope, unrelated to the accessor
[15:23:49] __Yiota: has joined #ruby
[15:23:54] matthewd: You need `self.thing = ..` to call the accessor... and then yes, you'll need to put it in initialize
[15:23:56] cjohnson: Ok so is the only difference the fact that I can access Foo.thing
[15:24:03] cjohnson: if it's @thing
[15:24:13] cjohnson: But if it's thing = 'my thing' then regardless of attr_* I can't call Foo.thing
[15:24:15] elomatreb: No, you can access Foo.new.thing, important difference
[15:25:06] matthewd: Ruby @x == JS this.x (approximately)
[15:25:13] havenwood: cjohnson: `attr_accessor :thing` gets and sets `@thing` with the #thing and #thing= methods. Internally you can get and set `@thing` directly
[15:25:39] ur5us: has joined #ruby
[15:25:49] cjohnson: Ok so the attr_* stuff is more for external use, but internally you can just access the var directly using @. which will bypass getters and setters logic
[15:25:50] matthewd: Ruby `foo = 1` == JS `let foo = 1`
[15:26:00] cjohnson: Ok, makes sense
[15:26:10] apeiros: cjohnson: you can mostly forget about @@ and $
[15:26:16] elomatreb: Re-implementing the attr_* methods is a great exercise btw
[15:26:20] apeiros: they should only be used in exceedingly rare occasions
[15:26:27] cjohnson: Oh right and for "static class" variables that's where you do class Foo; self.static_thing = 'my static value'; end
[15:26:32] matthewd: Yes; attr_accessor is a shortcut for `def foo; @foo; end; def foo=(value); @foo = value; end`
[15:26:50] cjohnson: And that gives me Foo.static_thing
[15:27:09] apeiros: class << Foo; attr_accessor :static_thing; end
[15:27:15] apeiros: for funsies
[15:27:23] elomatreb: No, there are no properties in Ruby like in Javascript. Everything you access from "outside" a class is a method
[15:27:27] apeiros: usually done via `class Foo; class << self; …; end; end`
[15:27:32] apeiros: (since self == Foo in that context)
[15:28:25] cjohnson: elomatreb: sorry, ignoring the method part. Object.keys in JS might be defined in ruby as class Object; def self.keys... end; end
[15:28:54] cjohnson: But Object#hasOwnProperty might be class Object; def hasOwnProperty...; end; end
[15:28:56] olivier__: has joined #ruby
[15:29:00] apeiros: or directly: def Object.keys; …; end
[15:29:09] apeiros: which btw. works for any object
[15:29:29] apeiros: >> x = "hello"; def x.only_this_string; "#{self} woot!"; end; x.only_this_string
[15:29:30] ruby[bot]: apeiros: # => "hello woot!" (https://eval.in/807909)
[15:29:40] matthewd: Note that JS properties and methods live in the same namespace; that is not so in Ruby
[15:29:51] cjohnson: matthewd: can you expand on that?
[15:29:55] elomatreb: Almost any, no? Can't do that with immediate thingies I think?
[15:29:56] matthewd: `self.foo` and `@foo` are unrelated
[15:30:06] apeiros: elomatreb: correct
[15:30:18] cjohnson: matthewd: because self.foo defines it on the class but @foo defines it on the instance?
[15:30:19] matthewd: (unless the 'foo' method happens to use @foo internally, for example)
[15:30:19] apeiros: elomatreb: also some other objects which chose to emulate immediates (Floats e.g.)
[15:30:42] matthewd: cjohnson: No, because instance variables and methods are unrelated
[15:30:49] apeiros: cjohnson: he means call-site
[15:31:15] ascarter: has joined #ruby
[15:31:17] gothicsouth: has joined #ruby
[15:31:22] safetypin: has joined #ruby
[15:31:25] baweaver: BART got delayed, so coffee shop time
[15:31:25] apeiros: >> class Foo; def initialize; @foo = 123; end; def foo; 789; end; def bar; {@foo: @foo, foo: self.foo}; end; end; Foo.new.bar
[15:31:26] ruby[bot]: apeiros: # => /tmp/execpad-b41d220cf9d4/source-b41d220cf9d4:2: syntax error, unexpected ':', expecting => ...check link for more (https://eval.in/807910)
[15:31:36] apeiros: >> class Foo; def initialize; @foo = 123; end; def foo; 789; end; def bar; {"@foo": @foo, foo: self.foo}; end; end; Foo.new.bar
[15:31:38] ruby[bot]: apeiros: # => {:@foo=>123, :foo=>789} (https://eval.in/807911)
[15:31:50] apeiros: right, :@foo works, @foo: doesn't.
[15:31:56] apeiros: ACTION stumbled over that before…
[15:32:20] apeiros: cjohnson: like ^
[15:32:33] elomatreb: apeiros' fancy client collapses ... into a proper character, I'm jealous
[15:32:45] apeiros: elomatreb: no, I type it properly
[15:32:51] apeiros: opt-. is … here
[15:32:59] olivier__: has joined #ruby
[15:33:16] apeiros: with osx, you could set up a global short-cut for ... to collapse, though
[15:33:36] apeiros: btw., I mostly type it properly because it's less effort :D
[15:33:37] Flonk: has joined #ruby
[15:33:48] baweaver: apeiros: I'd hate OSX if it auto-collapsed that
[15:33:50] apeiros: ACTION is the laziest of all lazy bastards
[15:33:54] brent__: has joined #ruby
[15:33:55] apeiros: baweaver: js? :D
[15:34:08] baweaver: think ranges as well
[15:34:24] apeiros: oh, right. I think I actually rarely use exclusive ranges.
[15:34:44] olivier__: has joined #ruby
[15:34:49] baweaver: but yeah, js too
[15:34:50] chouhoulis: has joined #ruby
[15:34:50] apeiros: maaaan, I really *love* how spreadsheet gem randomly converts dates to Date instances or Floats</sarcasm>
[15:36:48] baweaver: apeiros: ask zenspider about rspec making their own inspect / pretty print interceptors
[15:36:53] __Yiota: has joined #ruby
[15:37:27] apeiros: baweaver: bah, zenspider made his own NilClass#method_missing black hole…
[15:37:38] apeiros: so he clearly takes the cake in that regard :-p
[15:37:43] baweaver: karma it is then
[15:38:09] apeiros: anyway, all those are/were deterministic
[15:38:29] baweaver: well, between that and what people like me, havenwood, Ox0dea, and banisterfiend have done to the language we're all due for some karmic fallout
[15:38:31] apeiros: I can't figure out when spreadsheet behaves one way or the other. I run it twice on the same data with differing results.
[15:38:45] brent__: has joined #ruby
[15:39:16] baweaver: set_trace_func / binding.pry if value is a String and matches your data?
[15:39:44] baweaver: that way you have an interceptor that can trace the caller wherever that value happens to come up as a string
[15:40:59] baweaver: cjohnson: https://aphyr.com/posts/173-monkeypatching-is-for-wimps-use-set-trace-func
[15:41:03] baweaver: required reading :D
[15:42:29] baweaver: it's one of apeiros's favorites
[15:42:38] apeiros: ooooh dear
[15:42:44] apeiros: I figured why
[15:43:03] apeiros: I do: data = sheet.to_a; data.map! { |c1, c1, …| }
[15:43:11] apeiros: I don't do *anything* with the column in question
[15:43:40] apeiros: but! data is not an array of arrays, it's an array of Spreadsheet::Excel::Row's, and splatting that converts
[15:44:25] apeiros: I'm not quite sure why, though, since neither Row#to_a nor #to_ary exhibit that behavior when called directly
[15:45:37] elomatreb: "PHP programmers may want to try implementing $REGISTER_GLOBALS for Rack." -- Some people just want to watch the world burn?
[15:45:51] apeiros: but adding a data.map!(&:to_a) fixes the issue… I thought ruby invoked to_ary or to_a (first which it responds to) for splatting…
[15:46:18] perniciouscaffei: has joined #ruby
[15:46:22] apeiros: elomatreb: didn't php developers figure out already that that was a bad idea to begin with? o0
[15:46:40] cam27: has joined #ruby
[15:46:56] elomatreb: IIRC register_globals doesn't exist anymore for quite some time (5.5 I think?) and it was disabled by default long before that
[15:47:33] elomatreb: (The quote was from the article baweaver linked)
[15:47:41] ozcanesen: has joined #ruby
[15:47:58] dtzuzu: has joined #ruby
[15:48:28] apeiros: ok, I tested and ruby indeed tries to_ary first
[15:50:13] apeiros: oooooh wow wtf, Row#to_ary actually returns itself (a Row instance, not an Array), didn't notice because same inspect
[15:51:14] kitikonti: has joined #ruby
[15:51:50] mwlang: has joined #ruby
[15:52:04] mwlang: /join #rubyonrails
[15:52:26] baweaver: give it some space mwlang :D
[15:52:28] jrafanie: has joined #ruby
[15:52:54] mwlang: baweaver: heh, no kidding. apparently, my login was still “registering”
[15:53:32] apeiros: I really don't get what ruby does there. if I create a BasicObject which returns itself on to_ary, ruby only ever calls to_ary once and nothing else and then raises
[15:53:47] apeiros: no idea why it wouldn't raise for the Row which returns itself too
[15:54:30] apeiros: aaahahaha, figured. Row < Array
[15:54:50] apeiros: now I just have to figure why that in turn causes this weird conversion of Date -> Float
[15:56:30] belmoussaoui: has joined #ruby
[16:03:01] Cohedrin: has joined #ruby
[16:08:12] marxarelli: has joined #ruby
[16:11:56] solos: has joined #ruby
[16:12:57] belmoussaoui_: has joined #ruby
[16:14:51] beccamorgan: has joined #ruby
[16:15:53] cjohnson: baweaver: lol good article
[16:18:25] Exagone313: has joined #ruby
[16:20:10] beccamorgan: has joined #ruby
[16:23:18] acemo: has joined #ruby
[16:24:23] gusrub: has joined #ruby
[16:27:15] gusrub: has joined #ruby
[16:27:29] ltd: has joined #ruby
[16:29:37] nobitanobi: has joined #ruby
[16:29:45] yeticry_: has joined #ruby
[16:31:08] raspado: has joined #ruby
[16:32:36] nitric: has joined #ruby
[16:33:06] ascarter: has joined #ruby
[16:37:57] Nightmare: has joined #ruby
[16:38:31] synthroid: has joined #ruby
[16:39:06] Cohedrin: has joined #ruby
[16:43:32] SeepingN: has joined #ruby
[16:43:37] kubunto|afk: has left #ruby: ()
[16:45:00] GodFather: has joined #ruby
[16:46:04] nowhereman: has joined #ruby
[16:46:15] kies: has joined #ruby
[16:46:29] muelleme: has joined #ruby
[16:48:10] ruby-lang972: has joined #ruby
[16:48:56] hobodave: has joined #ruby
[16:49:20] dcunit3d: has joined #ruby
[16:49:28] __Yiota: has joined #ruby
[16:51:30] u0_a190: has joined #ruby
[16:56:21] gusrub: has joined #ruby
[16:57:09] mtkd: has joined #ruby
[16:59:16] belmoussaoui: has joined #ruby
[17:00:36] belmoussaoui_: has joined #ruby
[17:01:40] yottanami: has joined #ruby
[17:04:01] hutch34: has joined #ruby
[17:05:19] jrafanie: has joined #ruby
[17:05:35] Nightmare: has joined #ruby
[17:05:52] Fernando-Basso: has joined #ruby
[17:05:56] haylon: has joined #ruby
[17:07:47] belmoussaoui: has joined #ruby
[17:08:09] haylon: has joined #ruby
[17:09:44] duderonomy: has joined #ruby
[17:09:47] olivier__: has joined #ruby
[17:10:02] Cohedrin: has joined #ruby
[17:10:29] belmoussaoui: has joined #ruby
[17:12:24] lf_an: has joined #ruby
[17:13:13] lf_an: has left #ruby: ()
[17:21:26] machinewar: has joined #ruby
[17:22:21] mikecmpbll: has joined #ruby
[17:22:47] chalkmonster: has joined #ruby
[17:23:27] BTRE: has joined #ruby
[17:24:09] belmoussaoui: has joined #ruby
[17:26:08] gusrub: has joined #ruby
[17:26:25] ur5us: has joined #ruby
[17:29:21] belmoussaoui: has joined #ruby
[17:32:06] nobitano_: has joined #ruby
[17:33:12] shinnya: has joined #ruby
[17:33:32] ldnunes: has joined #ruby
[17:33:54] gothicsouth: has joined #ruby
[17:34:49] belmoussaoui: has joined #ruby
[17:35:30] oleingem_: has joined #ruby
[17:36:05] uZiel: has joined #ruby
[17:36:26] kenichi: ACTION waves
[17:37:22] dain: has joined #ruby
[17:41:34] hutch34: has joined #ruby
[17:43:09] Didac: has joined #ruby
[17:46:22] jane_booty_doe: has joined #ruby
[17:47:56] GinoMan: has joined #ruby
[17:49:11] normie1: has joined #ruby
[17:50:01] olivier__: has joined #ruby
[17:50:32] mim1k: has joined #ruby
[17:50:34] beccamorgan: has joined #ruby
[17:51:17] DLSteve_: has joined #ruby
[17:51:30] dc2: has joined #ruby
[17:53:37] belmoussaoui: has joined #ruby
[17:53:42] yottanami: has joined #ruby
[17:54:16] beccamorgan: has joined #ruby
[17:56:28] hobodave: has joined #ruby
[17:59:01] lxsameer: has joined #ruby
[17:59:29] kirun: has joined #ruby
[18:03:12] donald: has joined #ruby
[18:03:48] jgt: has joined #ruby
[18:04:27] donald: is there a french irc channel about ruby?
[18:04:42] apeiros: ?channels donald
[18:04:42] ruby[bot]: donald: see http://ruby-community.com/pages/channels for a list of Ruby related channels on Freenode
[18:04:59] apeiros: #ruby.fr as it seems
[18:18:30] muelleme: has joined #ruby
[18:19:15] faces: has joined #ruby
[18:19:25] Eiam: has joined #ruby
[18:19:31] tAn: has joined #ruby
[18:19:42] hutch34: has joined #ruby
[18:24:31] beccamorgan: has joined #ruby
[18:24:40] Ferdroid: has joined #ruby
[18:24:54] belmoussaoui: has joined #ruby
[18:29:32] beccamorgan: has joined #ruby
[18:29:41] yottanami1: has joined #ruby
[18:32:20] conta2: has joined #ruby
[18:32:56] lxsameer: has joined #ruby
[18:33:27] nobitanobi: has joined #ruby
[18:33:33] Exagone313: has joined #ruby
[18:40:21] pazzaz: has joined #ruby
[18:40:23] tAn: has joined #ruby
[18:41:49] rohitpaulk: has joined #ruby
[18:44:55] pazzaz: has joined #ruby
[18:51:17] hobodave: has joined #ruby
[18:52:23] patarr1: has joined #ruby
[18:53:30] jusa: has joined #ruby
[18:55:56] im0nde: has joined #ruby
[18:59:35] olivier__: has joined #ruby
[19:02:05] roshanavand: has joined #ruby
[19:02:49] milardovich: has joined #ruby
[19:03:45] cdg: has joined #ruby
[19:04:06] olivier__: has joined #ruby
[19:05:30] mikecmpb_: has joined #ruby
[19:07:29] centrx: has joined #ruby
[19:07:30] centrx: has joined #ruby
[19:08:03] pazzaz: has joined #ruby
[19:08:45] synthroid: has joined #ruby
[19:13:48] pazzaz: has joined #ruby
[19:14:44] dionysus69: has joined #ruby
[19:15:29] cdg: has joined #ruby
[19:15:32] KeyJoo: has joined #ruby
[19:17:05] hobodave: has joined #ruby
[19:20:38] eightlimbed: has joined #ruby
[19:24:49] ur5us: has joined #ruby
[19:26:26] olivier__: has joined #ruby
[19:27:38] flyingX: has joined #ruby
[19:27:40] bougyman: manveru: ping
[19:28:04] apeiros: ACTION mitm's the ping: pong
[19:28:24] postmodern: has joined #ruby
[19:28:25] manveru: bougyman: pong
[19:28:49] mvenancio: has joined #ruby
[19:30:51] ledestin: has joined #ruby
[19:31:30] enterprisey: has joined #ruby
[19:32:09] rohitpaulk: has joined #ruby
[19:38:30] ur5us: has joined #ruby
[19:39:58] GodFather: has joined #ruby
[19:41:23] tristanp: has joined #ruby
[19:41:42] mvenancio: has joined #ruby
[19:42:00] matheussilva: has joined #ruby
[19:42:44] GodFather: has joined #ruby
[19:43:14] ecuanaso: has joined #ruby
[19:43:32] Dimik: has joined #ruby
[19:44:47] eightlimbs: has joined #ruby
[19:45:06] ule: Hey guys
[19:45:37] ule: I'm dealing with some CSV.perse thing and it's blowing up when it finds a weird character and the file is not UTF-8
[19:45:58] ule: I'm wondering if anyone had the same issue before and could share some thoughts
[19:46:52] mikee: has joined #ruby
[19:47:18] eightlimbs: has joined #ruby
[19:49:40] belmoussaoui: has joined #ruby
[19:51:26] ule: trying here this: string.encoding('utf-8', string.encoding.to_s)
[19:51:58] roamingdog: has joined #ruby
[19:52:41] yqt: has joined #ruby
[19:53:39] apeiros: ule: that makes little sense?
[19:54:04] apeiros: the second arg already *is* source encoding
[19:54:13] apeiros: i.e. defaults to String#encoding
[19:55:13] pwnd_nsfw`: has joined #ruby
[19:56:18] ule: apeiros: exactly, I actually just need one argument
[19:56:26] ule: good catch
[19:56:51] hahuang65: has joined #ruby
[19:59:17] patarr: has joined #ruby
[20:01:30] cdg_: has joined #ruby
[20:03:57] haylon: has joined #ruby
[20:04:07] DLSteve_: has joined #ruby
[20:06:23] cats: has joined #ruby
[20:08:10] belmoussaoui_: has joined #ruby
[20:08:15] ule: https://gist.github.com/anonymous/0eb43ff7fc33a05babe8bc6b7cb70fdf
[20:08:22] ule: apeiros: what do you think?
[20:10:15] Keltia: has joined #ruby
[20:10:39] jackrandom: has joined #ruby
[20:11:29] marr: has joined #ruby
[20:14:54] belmoussaoui: has joined #ruby
[20:15:21] apeiros: ule: I think that I wonder why your string contains \x86
[20:15:39] Pumukel: has joined #ruby
[20:15:50] apeiros: String#scrub will get rid of it, but that's fighting symptoms. I wonder about the root of your issues.
[20:15:56] ule: .encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
[20:16:00] ule: this made the trick
[20:16:37] ule: apeiros: that x86 is something that is showing up from some client .csv
[20:16:41] ule: don't ask me why
[20:16:48] apeiros: but I do ask you why.
[20:16:55] apeiros: your solution is bad and you shouldn't use it. scrub is the way.
[20:17:05] apeiros: your solution will mangle and break tons of valid input.
[20:17:05] ule: apeiros: OK
[20:17:36] apeiros: >> "hägar@hølgerson.com".encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
[20:17:37] ruby[bot]: apeiros: # => "hgar@hlgerson.com" (https://eval.in/808030)
[20:18:00] matthewd: If the file's not utf-8, it might be wiser to read it in the encoding it's actually using
[20:18:22] ule: matthewd: but my db is utf-8 so I need to convert it anyways
[20:18:36] __Yiota: has joined #ruby
[20:18:47] ule: apeiros: checking that scrub()
[20:18:53] matthewd: Yes. *Convert*.
[20:19:10] apeiros: matthewd: and that'd be "but I ask" :)
[20:19:16] ule: matthewd: but that was the problem.. I converted and it changed to \86
[20:19:18] apeiros: ule: how do you figure your input is utf-8?
[20:19:28] belmoussaoui_: has joined #ruby
[20:19:32] ule: apeiros: string.encoding
[20:19:36] apeiros: well, you *think* you converted it. we saw how you're "converting" stuff above.
[20:19:48] apeiros: ule: see, that doesn't do what you think it does.
[20:19:57] apeiros: String#encoding tells you what *you* told ruby the encoding was
[20:20:08] apeiros: and *you* told ruby in this case most probably by just keeping the defaults
[20:21:09] apeiros: so no, String#encoding is not a way to figure the encoding of data you're reading. it's a way to figure as what ruby will treat it (which in turn is based on what you tell it to)
[20:21:10] ule: apeiros: how can I just identify if the string has some fancy characters like those ones you sent in your german/swiss email?
[20:21:54] apeiros: string.b.scan(/[\x80-\xff]{2,}/)
[20:22:02] apeiros: run that, show us the first couple results
[20:22:47] apeiros: whoops, add an n flag to the regex (//n)
[20:23:40] belmoussaoui: has joined #ruby
[20:23:52] apeiros: hm, maybe this is even better: string.b.scan(/\w*[\x80-\xff]{2,}\w*/n)
[20:23:58] apeiros: will give us a bit of context
[20:24:22] ule: ok lemme check
[20:24:37] apeiros: (you can output it using p, e.g. `p string.b.scan(/\w*[\x80-\xff]{2,}\w*/n).first(5)`)
[20:24:37] roamingdog: has joined #ruby
[20:25:18] dminuoso: apeiros: Do you have that encoding gist handy?
[20:25:32] apeiros: I really should finish that
[20:25:38] olivier__: has joined #ruby
[20:25:43] ruby[bot]: check https://gist.github.com/apeiros/39acc5b486f932403638 - it might contain useful informations to solve your encoding problems
[20:26:00] apeiros: ule: ^ should read that too
[20:26:11] matheussilva: has left #ruby: ("Good Bye")
[20:26:16] brent__: has joined #ruby
[20:26:16] apeiros: also tell me if there's things you don't understand, or tell me what you liked/helped you.
[20:26:33] brent__: has joined #ruby
[20:26:34] apeiros: is o7 an arrow?
[20:26:38] dminuoso: apeiros: You should at least refer to mojibaking by name, since it's a common term.
[20:26:46] dminuoso: apeiros: No that's a saluting person.
[20:27:04] apeiros: ok, that's what I thought first, but didn't seem to make sense :D
[20:27:09] apeiros: mojibaking?
[20:27:37] apeiros: oh, didn't know that term. I guess I should. can you comment on the gist?
[20:27:46] dminuoso: apeiros: mojibake is when you interpret a text with a different encoding than was used when encoding.
[20:28:00] apeiros: yes, seen. already on https://de.wikipedia.org/wiki/Zeichensalat
[20:28:08] apeiros: german++ :D
[20:28:14] apeiros: "character salad"
[20:28:25] apeiros: or rather "glyphsalad"
[20:28:48] dminuoso: Nice recovery there.
[20:28:53] ule: apeiros: I'm definitely gonna be reading that
[20:29:23] dminuoso: apeiros: Had a funny discussion the other day when someone asked about his language he was designing how to handle strings. And I asked him: "What do you understand as a string?"
[20:29:38] baweaver: Dumme Verwirrung?
[20:29:56] apeiros: dminuoso: do go on? :)
[20:30:21] apeiros: ACTION actually has a ton of concepts on how to implement strings low level to handle different situations performantly or compactly
[20:30:48] dminuoso: apeiros: Ended up displaying Haskell is the best example, since it takes all 3 ways to consider "strings" and provides them as different types.
[20:31:15] apeiros: says "all" and "3" in the same phrase…
[20:31:30] apeiros: I'm not sure which one of these you consider correct :-p
[20:31:37] apeiros: which 3 ways does haskell provide?
[20:31:55] dminuoso: apeiros: String, Text and ByteString
[20:31:57] apeiros: I guess bytearray and character/codepoint array? which is the third?
[20:32:21] yottanami1: has joined #ruby
[20:32:36] ule: apeiros: it's actually showing []
[20:32:56] apeiros: ule: ok, then you most likely do not have utf-8
[20:33:08] apeiros: and given the string you already showed, it's not utf-16 or -32 either
[20:33:28] dminuoso: apeiros: Well and then there is [Char] ..
[20:33:29] ule: I'm getting this with string.encoding: #<Encoding:ASCII-8BIT>
[20:33:37] apeiros: ule: change to `p string.b.scan(/\w*[\x80-\xff]+\w*/n).first(5)` please
[20:33:48] apeiros: yes. string.b changes the encoding to ascii-8bit
[20:33:59] ule: ["com\x86"]
[20:34:13] apeiros: in *all* your input data, all you get is the above?
[20:34:20] dminuoso: apeiros: So the question is: Is a string just a concatenation of bytes (C char array). Is it a concatenation of code points? (Thing c++ std::basic_string), if so, how are multi-byte code points implemented?
[20:34:32] ule: apeiros: it's just one line of the csv
[20:34:36] Dwarf-br: has joined #ruby
[20:34:42] dminuoso: Is it done with wide characters? Or spanning over multiple single characters? if so, how is length/truncation handled in the latter
[20:34:48] dminuoso: Is encoding information attached?
[20:34:55] dminuoso: Or maybe font face information
[20:35:08] apeiros: ule: … if you think a *single* point of information is enough, you're wildly mistaken.
[20:35:13] dionysus70: has joined #ruby
[20:35:14] Fernando-Basso: has joined #ruby
[20:35:46] ule: apeiros: I mean.. in this .csv it's just one line.. but definitely I'm gonna get more in the future
[20:35:59] apeiros: "multibyte codepoint" the multibyte aspect is irrelevant if you handle it as codepoints (other than having to know the maximum value for a codepoint)
[20:36:06] dminuoso: apeiros: No it is not!
[20:36:19] apeiros: it is. because codepoint != bytes
[20:36:27] ace05: has joined #ruby
[20:36:29] dminuoso: apeiros: Think std::basic_string<wchar_t> and std::basic_string<char>
[20:36:45] dminuoso: apeiros: You can throw an UTF8 string into both.
[20:36:52] dminuoso: Linux uses the latter, Windows the former.
[20:37:08] dminuoso: The first one is far more comfortable to use but wastes tons of space.
[20:37:10] apeiros: if it matters, then you don't have a codepoint array.
[20:37:20] apeiros: you may have fancy facades, but in the end you have a bytearray.
[20:38:22] dminuoso: apeiros: My point is, there's enough examples to show how inconsistent implementations can be/
[20:38:25] apeiros: or rather, codepoint list (array already comes with a lot of connotation on how it's stored in memory)
[20:38:42] dminuoso: apeiros: This codepoint array is a nice idea (and Windows does this excessively - sadly), but it performs really horrible.
[20:38:54] dminuoso: It drastically increases cache pressure and increases memory usage.
[20:39:16] apeiros: I'd guess a 4byte array would perform quite well. it'd just use a ton of space.
[20:39:43] apeiros: but yeah, I doubt codepoint lists are the way to go for everyday strings
[20:39:47] dminuoso: apeiros: In worst case, and considering how most of the time you only use ASCII compatible codepoints, you quadruple the cache pressure.
[20:39:58] dminuoso: (Which is far worse than actual memory usage)
[20:40:19] apeiros: you can have a codepoint array which adapts to its data
[20:40:42] apeiros: that's the point I tried to make when I replaced array with list
[20:40:46] dminuoso: apeiros: Worst case would be a single non-ascii compatible codepoint in a long string then.
[20:40:52] dminuoso: Or would you use a linked list of arrays?
[20:40:54] apeiros: how you store it in memory is a different thing from what you store
[20:41:45] dminuoso: apeiros: Well if you say "array of codepoints" its already an implementation detail, isnt it?
[20:41:51] apeiros: or a skip list, or ropes, or a custom data format. sure.
[20:41:57] dminuoso: apeiros: I mean the naive user expects an "array of characters"
[20:41:59] dminuoso: whatever their codepoints are
[20:42:04] dminuoso: (Which is what Ruby does)
[20:42:17] apeiros: no, array really just means sequential data. but yes, hence my "array already comes with a lot of connotation on how it's stored in memory"
[20:42:28] apeiros: and hence my "list instead of array"
[20:42:50] apeiros: but there really isn't any loaded term for the abstract concept anymore
[20:43:13] apeiros: ule: well, from that single data point it looks like erroneous data.
[20:43:32] apeiros: ule: does the supplier of the data not tell you the encoding of the data? because really, that's the only *really* reliable way.
[20:43:52] belmoussaoui_: has joined #ruby
[20:50:08] gil_: has joined #ruby
[20:50:08] gil_: has joined #ruby
[20:52:15] ule: apeiros: Yeah.. I'm gonna investigate that
[20:52:59] ule: apeiros: for now, I believe that the best thing to do is catch these erroneous lines and throw a message saying "check this line, it must be wrong"
[20:53:15] cdg: has joined #ruby
[20:53:15] apeiros: that's sensible
[20:53:40] apeiros: have your strings encoded as utf-8, then you can use: string.valid_encoding?
[20:54:07] ule: I was doing this:
[20:54:11] ule: unless string.encoding.to_s.include?('UTF-8')
[20:54:38] apeiros: you're still not understanding what string.encoding is about
[20:55:05] apeiros: again, string.encoding is what YOU tell ruby. ruby doesn't perform any kind of magic to figure out which encoding data might use.
[20:55:46] apeiros: so all string.encoding.to_s.include?('UTF-8') does is test whether you're still using the same defaults (or explicit settings)
[20:58:04] gothicsouth: has joined #ruby
[20:58:57] jenrzzz: has joined #ruby
[20:58:57] jenrzzz: has joined #ruby
[20:59:06] ur5us: has joined #ruby
[21:00:02] belmoussaoui: has joined #ruby
[21:00:44] ule: how about: if string.force_encoding(Encoding::UTF_8).valid_encoding?
[21:01:30] ule: or scrub is the way to convert it?
[21:04:17] dminuoso: ule: Find out what encoding they use.
[21:04:21] dminuoso: Dont guess.
[21:04:22] apeiros: you really should read the link above
[21:04:46] dminuoso: ule: If you have to use valid_encoding?, chances are you are doing it wrong.
[21:04:47] tomphp: has joined #ruby
[21:04:48] apeiros: .scrub does not convert anything. all it does is remove bytes which do not represent a character in the current encoding.
[21:04:49] ule: dminuoso: It's not just one client.. could be any encoding
[21:05:10] belmoussaoui: has joined #ruby
[21:05:12] apeiros: and .valid_encoding? checks whether any such bytes are present
[21:05:27] ule: apeiros: make sense
[21:05:47] apeiros: dminuoso: I suggested .valid_encoding? and it makes sense for this task. assume it's utf-8, verify with .valid_encoding?, inform user that it contains data to be inspected if it's not valid.
[21:05:58] dminuoso: apeiros: I'd be lazy and use rchardet
[21:06:03] dminuoso: Because fuck encoding.
[21:06:11] apeiros: dminuoso: you'd make things worse
[21:06:25] apeiros: IME rchardet and consorts are terribad at correctly guessing the encoding.
[21:07:07] gil_: has joined #ruby
[21:07:07] gil_: has joined #ruby
[21:07:11] tomphp: has joined #ruby
[21:08:02] olivier__: has joined #ruby
[21:08:10] dminuoso: apeiros: It's bad enough I have to deal with CR+LF, LF, CR issues every week..
[21:08:21] apeiros: those are easy
[21:08:31] dminuoso: apeiros: That depends on what you are doing.
[21:08:33] apeiros: gsub(/\r\n?|\n/, "\n")
[21:08:47] dminuoso: apeiros: Do you do this everytime you File.read?
[21:08:50] apeiros: there, normalized to \n all variants I know about
[21:08:56] apeiros: no. but I consume sane data.
[21:09:04] dminuoso: apeiros: Heh.
[21:09:07] apeiros: I do it in one case where users can upload csv.
[21:09:25] apeiros: and there I have a custom heuristic to determine whether it's utf-8, utf-16, windows-latin1 or macroman
[21:09:43] dminuoso: apeiros: It's easy if you are limited to one particular language.
[21:09:54] apeiros: and a custom heuristic to determine whether it's craptastic excel csv which thinks the C in csv stands for "semicolon"
[21:09:54] ule: ACTION learning a lot about encoding
[21:09:54] dminuoso: apeiros: Do you have any French in your company?
[21:10:05] apeiros: dminuoso: yes and yes
[21:10:06] dminuoso: apeiros: haha!
[21:10:09] ule: ACTION starting to hate encoding as well
[21:10:21] apeiros: ule: don't. learn how it works
[21:10:30] dminuoso: ule: Go solve it by inventing a unified encoding for them a..
[21:10:35] ule: dminuoso: apeiros we have french/canadian encodings here as well
[21:10:36] apeiros: the only bad part about encodings is the lack of containers which contain the metadata.
[21:10:38] dminuoso: https://xkcd.com/927/
[21:10:40] Papierkorb: apeiros: We had that too in a prod app of ours. Exactly same use-case lawl. also, some tools giving utf8, others windows-*whatever*
[21:11:02] dminuoso: Papierkorb: Here I solved it by not accepting CSV anymore.
[21:11:23] dminuoso: We supply our own tools to deal with data, so that I control the encoding, not them.
[21:12:10] dminuoso: apeiros: And then there's the cases where PDF vendors use custom font faces to disallow copy pasting..
[21:12:25] dminuoso: apeiros: or the cases where you cant convert certain characters because users pick silly code points..
[21:12:29] belmoussaoui: has joined #ruby
[21:12:48] dminuoso: apeiros: :D
[21:12:48] apeiros: you know pdf has a custom encoding?
[21:12:53] ule: dminuoso: lol
[21:12:54] apeiros: it's insane
[21:13:01] dminuoso: PDF has all kinds of crazy shit.
[21:13:06] dminuoso: I opened a PDF with the PDF specification once.
[21:13:10] dminuoso: Preview hang up for 20s.
[21:13:11] ule: dminuoso: I like this idea not accepting .csv anymore
[21:13:19] Papierkorb: truth be told, no one ever used the words "sane" and "pdf" in the same sentence
[21:13:24] apeiros: also silly pdf vendors - all they have to do is render the fonts
[21:13:34] apeiros: and they're still silly because OCR
[21:13:39] apeiros: so yeah, fuck them
[21:13:45] dminuoso: apeiros: OCR is the only way to process some PDFs..
[21:13:51] apeiros: Papierkorb: it's a ton saner than .doc or .docx
[21:13:54] workmad3: has joined #ruby
[21:14:01] Papierkorb: apeiros: but who wouldn't want to be able to run custom code in PDFs?!
[21:14:12] dminuoso: I run custom code in power point now.
[21:14:14] apeiros: did I mention that I'm actually asleep for the last 15min?
[21:14:24] troys: has joined #ruby
[21:14:26] Papierkorb: apeiros: Look at photoshop files lol
[21:14:34] dminuoso: ACTION keeps track of apeiros' sleep pattern
[21:14:52] apeiros: Papierkorb: you're aware that postscript is touring complete and that there's things like sudoku solvers implemented in it?
[21:15:11] apeiros: and I bet pdf being the spiritual successor is touring complete too
[21:15:22] Papierkorb: apeiros: you can embed postscript in PDF
[21:15:30] apeiros: there you go
[21:16:27] mim1k: has joined #ruby
[21:16:43] apeiros: it's late! and I'm dreamtyping!
[21:16:51] apeiros: so give me a break!
[21:18:22] belmoussaoui: has joined #ruby
[21:19:14] jrafanie: has joined #ruby
[21:19:48] roamingdog: has joined #ruby
[21:20:16] Archrover: has joined #ruby
[21:20:38] roamingdog: has joined #ruby
[21:21:16] jackrandom: has joined #ruby
[21:21:23] roamingdog: has joined #ruby
[21:22:11] roamingdog: has joined #ruby
[21:23:00] roamingdog: has joined #ruby
[21:23:15] zacts: has joined #ruby
[21:23:27] dminuoso: How's the punning going
[21:23:41] baweaver: I've had a few gems
[21:23:50] roamingdog: has joined #ruby
[21:23:57] dminuoso: Tell me more
[21:24:28] belmoussaoui: has joined #ruby
[21:27:21] Cohedrin: has joined #ruby
[21:27:21] gothicsouth: has joined #ruby
[21:27:31] kiltzman: has joined #ruby
[21:29:46] belmoussaoui: has joined #ruby
[21:33:00] nertzy: has joined #ruby
[21:35:15] mikecmpbll: has joined #ruby
[21:42:47] al2o3-cr: i don't know, but i've had a few gills
[21:47:13] ascarter: has joined #ruby
[21:53:05] SpComb: has joined #ruby
[21:56:51] tomphp: has joined #ruby
[21:58:18] GinoMan: has joined #ruby
[22:00:09] im0nde: has joined #ruby
[22:02:37] weathermaker: has joined #ruby
[22:06:41] ecuanaso: has joined #ruby
[22:10:29] im0nde: has joined #ruby
[22:12:24] patarr: has joined #ruby
[22:15:05] gothicsouth: has joined #ruby
[22:18:41] Guest69: has joined #ruby
[22:19:08] HoierM: has joined #ruby
[22:23:57] ace05: has joined #ruby
[22:28:16] ace05_: has joined #ruby
[22:29:29] duderonomy: has joined #ruby
[22:29:56] Radar: has joined #ruby
[22:34:25] shtirlic: has joined #ruby
[22:40:17] weaksauce: has joined #ruby
[22:44:50] yottanami1: has joined #ruby
[22:45:17] minimalism: has joined #ruby
[22:46:36] yottanami1: has joined #ruby
[22:47:46] jusa: has joined #ruby
[22:48:01] ecuanaso: has joined #ruby
[22:54:21] hutch34: has joined #ruby
[22:55:12] yxhuvud: has joined #ruby
[22:55:47] Larahero: has joined #ruby
[22:56:46] yitsushi: has joined #ruby
[23:00:21] olivier__: has joined #ruby
[23:02:21] roamingdog: has joined #ruby
[23:02:36] alveric1: has joined #ruby
[23:07:35] GodFather: has joined #ruby
[23:11:42] gusrub: has joined #ruby
[23:14:29] dtzuzu: has joined #ruby
[23:17:00] mim1k: has joined #ruby
[23:17:11] raspado: has joined #ruby
[23:24:08] marxarelli: has joined #ruby
[23:28:42] cam27: has joined #ruby
[23:32:05] roamingdog: has joined #ruby
[23:32:56] roamingdog: has joined #ruby
[23:33:46] roamingdog: has joined #ruby
[23:34:30] roamingdog: has joined #ruby
[23:35:20] roamingdog: has joined #ruby
[23:36:42] Guest69: has joined #ruby
[23:36:42] railswebdev: has joined #ruby
[23:38:56] cam27: has joined #ruby
[23:40:01] kies: has joined #ruby
[23:40:30] apparition: has joined #ruby
[23:45:21] Cohedrin: has joined #ruby
[23:52:10] milardovich: has joined #ruby
[23:59:55] hutch34: has joined #ruby