#ruby - 23 February 2018
« Back 1 day Forward 1 day »
[00:06:28] ruby[bot]: +bbbb chouhoulis!*@*$#ruby-fix-your-connection chouhoul_!*@*$#ruby-fix-your-connection chouhou__!*@*$#ruby-fix-your-connection chouho___!*@*$#ruby-fix-your-connection
[00:06:28] ruby[bot]: +bb chouh____!*@*$#ruby-fix-your-connection *!*@50-207-64-46-static.hfc.comcastbusiness.net$#ruby-fix-your-connection
[00:06:32] ruby[bot]: -bbbb *!*@gateway/web/cgi-irc/kiwiirc.com/ip.18.104.22.168$#ruby-banned WHITEPRIDE!*@*$#ruby-banned THEKKKLAN!*@*$#ruby-banned *!*@gateway/web/freenode/ip.22.214.171.124$#ruby-banned
[00:06:32] ruby[bot]: -bb *!ac3a0c01@gateway/web/freenode/ip.126.96.36.199$#ruby-banned chatter*!*@*$#ruby-banned
[00:08:45] keithy: its working as expected! but somethings are a bit fragile… it doesnt make it through a whole disk
[00:09:25] zenspider: keithy: you're burning up cred here with your not listening, not answering, etc.
[00:20:29] keithy: My last argument was not expecting someone to try and turn it into a hash, it only knew to_str
[00:22:16] Radar: [11:09:25] <zenspider> keithy: you're burning up cred here with your not listening, not answering, etc. <- yeah this
[00:23:45] Radar: [10:56:58] <havenwood> keithy: And you've tried using Find.find? Show us the code you have so far?
[00:24:14] keithy: hello I have used find find I have tested it on 1TB of disk and its does what you said
[00:27:07] havenwood: keithy: If you run into issues understanding spats or blocks, so us the code where things went wrong and we can help.
[00:28:18] keithy: I then said that I apparently ran into an issue which ruby I dont think ruby had 15 years ago
[00:38:51] zenspider: everything about splats and blocks (and block args) have been the same for the past 15 years.
[01:46:36] zenspider: how strange... I'm working on some code that generates an Enumerable via chunk_while... if I do `p x.to_a` some later code raises with ZeroDivisionError. If I comment that code out, it doesn't...
[12:49:30] dminuoso: floppydh: The point that phaul made is valid, but it's not the real reason we actually do it.
[12:49:36] floppydh: phaul: they seem more heavyweight? - you hash each "string" and store both the interna-identifier and the string-name?
[12:50:30] floppydh: hmmmm... one argument I heard is that it's there for semantics, because if you see a string, it could be a lot of things, but if you use a symbol, it limits the way they can be used?
[12:51:16] dminuoso: floppydh: inside of ruby the purpose of "symbol" is basically to identify things (where comparing to find a match is necessary)
[12:51:26] floppydh: but it seems highly questionable that string-comparisons are really a performance problem in your program and if performance matters why are you using ruby in the first place?
[12:51:29] dminuoso: methods and variables are two examples that are identified via symbols internally
[12:51:56] phaul: I think symbols are semmantically different from strings. They serve different purpose, so the real reason is not a perfomrance optimization
[12:52:17] ruby[bot]: dminuoso: I have disassembled your code, the result is at https://eval.in/961830
[12:56:25] phaul: hm. was metaprogramming all with Strings back then? I mean metaprogramming is all "userland" isn;t it?
[12:56:39] dminuoso: floppydh: the principle idea is this: ruby provides a function called rb_intern()
[12:58:59] dminuoso: Which gives you a universal way of turning a string into an integer that can be compared with at O(1) complexity
[12:59:23] dminuoso: That mapping is referentially transparent, so every time you pass the same string, you get the same "number representation" back
[13:00:10] dminuoso: Giving you the "string look" while using the rb_intern mapping as the actual internal value
[13:04:08] dminuoso: phaul: The core difference is this: In order to compare two strings for equality you have to use #== which is O(n). #object_id wont work because
[13:05:35] floppydh: but I guess the semantics point still makes sense, when you see a symbol you know its used as a reference from/to something - a plain string alone would require additional context
[13:06:11] ruby[bot]: dminuoso: # => [:, :try_convert, :new, :allocate, :superclass, :<=>, :module_exec, :class_exec, :<=, :>=, :==, := ...check link for more (https://eval.in/961846)
[13:06:52] phaul: dminuoso: just what I wanted to point out. I think this is the key, the rest ie complexity is just implementation details
[13:06:56] ruby[bot]: dminuoso: # => [:Object, :Module, :Class, :BasicObject, :Kernel, :NilClass, :NIL, :Data, :TrueClass, :TRUE, :FalseC ...check link for more (https://eval.in/961847)
[13:07:29] ruby[bot]: dminuoso: # => undefined method `instance_vars' for #<struct a=1> ...check link for more (https://eval.in/961848)
[13:07:32] floppydh: I guess you can debate how much of a benefit they actually end up being in the semantics/context case, excluding implementation details
[13:08:58] dminuoso: In reality its just a number, Symbols reify that by giving us a string looking representation
[13:10:28] dminuoso: floppydh: You can think of Symbol as a transparent access to the intern lookup table. =P
[13:15:58] ruby[bot]: dminuoso: # => can't define singleton (TypeError) ...check link for more (https://eval.in/961851)
[13:24:44] ruby[bot]: dminuoso: # => /tmp/execpad-8b70edea28fd/source-8b70edea28fd:2: syntax error, unexpected tSYMBEG ...check link for more (https://eval.in/961873)
[13:24:50] ruby[bot]: dminuoso: # => /tmp/execpad-9a98a6f2d029/source-9a98a6f2d029:2: can't define singleton method for literals ...check link for more (https://eval.in/961874)
[13:25:37] phaul: right, but where Im confused is method lookup on them. So does ruby implement a specail case for method lookups on Symbols?
[15:03:21] NL3limin4t0r: Zaab1t: If you have a pluralsight account you should watch the "Ruby Fundamentals" cource.
[15:04:45] NL3limin4t0r: After knowing the fundamentals I learned the most by keeping the official ruby doc by hand. Every core object and method is explained in detail. https://ruby-doc.org/core-2.5.0/
[15:07:03] NL3limin4t0r: I also have a question, I'm searching for a equivalence operator, but can't seem to find it. Does anyone know if Ruby has one?
[15:08:12] NL3limin4t0r: I basicly want that `true <operator> true` equals `true` and `false <operator> false` equals `true`.
[17:13:24] havenwood: adgtl: Rails has ActionCable with WebSockets and fallbacks these days. Rails apps like Discourse prefer MessageBus, which is a similar channel but disfavors WebSockets.
[17:14:40] havenwood: adgtl: We use gRPC, which is worth looking at if you haven't: https://grpc.io/docs/quickstart/ruby.html
[17:15:53] havenwood: adgtl: It's Elixir not Ruby, but Phoenix Channels just got HTTP/2 support and deserve a mention: https://hexdocs.pm/phoenix/channels.html
[17:17:52] havenwood: adgtl: AnyCabe is an ActionCable replacement that uses gRPC with Protobufs over HTTP/2: https://github.com/anycable/anycable#readme
[17:18:50] havenwood: adgtl: gRPC with Protocol Buffers over HTTP/2 seems like a nice way forward to me.
[17:19:26] havenwood: adgtl: An aside, but here's a pure Ruby implementation of the HTTP/2 protocol: https://github.com/igrigorik/http-2#readme
[18:21:48] Gnut: If i'm creating a ruby gem, is it okay to have multiple libraries or are they all supposed to be under the same parent namespace
[18:24:05] havenwood: Gnut: A single lib/ directory with gem_name_here.rb and a gem_name_here/ directory: http://guides.rubygems.org/patterns/#consistent-naming
[18:24:57] havenwood: Gnut: Other Ruby files go in lib/gem_name_here/, for example: lib/gem_name_here/version.rb
[18:25:41] havenwood: Gnut: If you take a look at a few gem's lib/ dir and sub-dirs you will see the pattern.
[18:27:22] havenwood: tomlukeywood: It also can signify calling a class method, but you'll probably see it a lot less for that these days.
[18:28:45] havenwood: tomlukeywood: The Net module is a namespace that contains various classes like HTTP and FTP.
[18:30:08] dminuoso: Put that into a few places, and pray some unwary programmer will see it in a few years.
[18:30:19] Gnut: tomlukeywood: The snipper you pasted is how you acces this fucntion https://github.com/ruby/ruby/blob/trunk/lib/net/http.rb#L460
[18:30:50] Gnut: tomlukeywood: If you scroll up you can see it's in the `HTTP` class and the `HTTP` class is in the `Net` module
[18:31:05] dminuoso: >> Object.const_get(:Object)::Object.const_get(Object)::Object.const_get(:Object)
[18:31:07] ruby[bot]: dminuoso: # => no implicit conversion of Class into String (TypeError) ...check link for more (https://eval.in/962037)
[18:31:18] dminuoso: >> Object.const_get(:Object)::Object.const_get(:Object)::Object.const_get(:Object)
[18:33:37] ruby[bot]: dminuoso: # => uninitialized constant #<Class:A>::B (NameError) ...check link for more (https://eval.in/962070)
[19:58:26] swein: doh, I was reading all of ruby-doc, got to uniq and gave up to ask. it was right below
[20:02:54] dalitom: hey guys, how to compare 2 arrays.... list1 = [1,2,3] and list2 = [3,1,2], how to check if they contain same elements
[20:09:55] gizmore: dalitom: https://stackoverflow.com/questions/5013880/ruby-compare-2-arrays-for-matches-and-count-the-number-of-match-instances ??
[20:35:23] swein: I have an in depth question, lets say I have a hash of keys[1,2,3] and key=[a-z], but key 2 and 3 have only varying letters from the alphabet. What's a good way to insert empty strings "" to provide spacing so when creating CSV rows, it will all line up with columns of A's B's C's,
[20:36:30] swein: I may need to read class CSV better to see if it provides built in ability to do the searching/scanning and moving columns of like row header values
[21:02:33] Terens: I am using concurrent ruby. I want to build a simple downloader ( a class?) that would download a specific file via http , and update the download progress.
[22:19:38] gizmore: if i want a datatype like "email" i gotta write all the stuff all over again... like varchar(255), charset, the validators, etc
[22:21:30] gizmore: ActiveRecord does not feature composed primary keys, like userid INT(11) friendid INT(11)
[22:26:31] gizmore: i had to work with rails for 2 or 3 years.... then did a private project for 1 or 2 years
[22:27:48] gizmore: i redid all in php.... with type hinting.... and i think i can beat AR in some aspects (not all)
[22:29:59] havenwood: gizmore: I think you'll find you can extend ActiveRecord types as you see fit. I don't really agree with any of your criticisms.
[22:32:21] havenwood: gizmore: That's not DRY. The thing is what it is. It's not the Ruby way to repeat things for the sake of the machine.
[22:32:59] havenwood: gizmore: If you like Ruby but would prefer explicit types, consider Crystal. Pretty sure I suggest this every time you come here to talk about PHP type hinting.
[22:33:43] havenwood: gizmore: Ruby 3 might include some static type analysis. It won't include anything you type inline in your code. It's a tool that you can use.
[22:39:00] havenwood: gizmore: The Ruby 3 plans will allow for all of that, without you having to change your code.
[22:41:57] havenwood: [T]he third major goal of the Ruby 3 is adding some kind of static typing while keeping the duck typing, so some kind of structure for soft-typing or something like that... It’s just a compile time check. [Y]ou can use that kind of information in IDEs so that the editors can use that data for their code completion..." ~ Matz
[22:44:40] gizmore: types like GDT_PhoneNumber add some validations or additional features.... all covered by type hinting, making it easy to write code using the types
[22:45:56] gizmore: the "countrycodes" function would be suggested by your IDE... because "make()" returns self... "GDT_PhoneNumber" in this case
[22:48:03] gizmore: havenwood: my best ruby code is in "ricer2" project..... have a look https://github.com/gizmore/ricer2
[23:05:58] Mike11: I am looking for clean (maybe functional-style) way to get line/column position from bytes offset in a file
[23:13:45] havenwood: Guest64757: You can change the syntax. Maybe you'd like creating a DSL in Ruby so you have your own mini-language.