#ruby - 09 December 2017
« Back 1 day Forward 1 day »
[00:11:07] madprops: apeiros, im not really sure. But someone is having trouble with it for some reason "msg.js uses the \` character, which does not work too well with
[00:18:07] JinJin: does anyone here have experience with TCP connections? I have a server that accepts connections using accept. I can write to sockets when I call TCPSocket.new(), but when I try to write to a socket that I've accepted, it doesn't work. Is this behavior expected?
[00:19:27] ruby[bot]: JinJin: We can't help you without your code, please post it to https://gist.github.com
[00:21:11] dminuoso: JinJin: And let this be the last day you have heard about $ and global variables.
[00:22:18] JinJin: If I have a = TCPServer.new someportnumber. And I receive a socket for instance: socket = a.accept. Can I write to it? As in socket.write(...)
[00:23:18] JinJin: I've been doing so with my code, I can only receive or establish connections. I can't write to clients that I've accepted
[00:34:05] apeiros: as for your code sample - yeah, no. not gonna read that much code. write a simple tcpserver, go from there.
[00:49:10] apeiros: JinJin: I partially read your code. I don't see your code to create a socket actually being called.
[00:49:37] apeiros: also I don't see you writing to a socket accepted by the server except for when you receive data on it before
[00:50:07] apeiros: IMO make sure your assumptions are actually correct. that you do actually create a socket, that the server actually accepts a connection, that you actually write from the client side, etc.
[00:53:58] JinJin: apeiros: In my code on line 319, i accept incoming connections and save them on line 368. But in line 405 when I write, nodes I've accepted don't receive anything
[03:23:00] BuildTheRobots: good evening people. If i have an array including a negative number, how can I have a.max do the sensible thing (in this case return +7, not -10 as the largest number)
[04:19:18] BuildTheRobots: baweaver, i might have messed up my example, in fact i did, these are values in a hash, not an array
[04:20:38] ruby[bot]: baweaver: # => undefined method `>' for [:a, 10]:Array (NoMethodError) ...check link for more (https://eval.in/915684)
[04:20:43] BuildTheRobots: hashes give two arguments? for max_by? apologies, i've only been using ruby for a few days o.0
[04:21:06] ruby[bot]: baweaver: # => comparison of Symbol with 0 failed (ArgumentError) ...check link for more (https://eval.in/915685)
[04:22:25] BuildTheRobots: for contect, i got about 5 steps into a codeweavers learning ruby course and then got distracted actually tring to use it... so I'm kinda blundering forward solving adventofcode problems without yet understanding objects o.0
[04:58:24] BuildTheRobots: i do bits of ops, so previously have been hacking scripts in perl, but i'm the first to point out i'm not a dev. A friend is using RoR so it seemed like a good excuse to learn ruby. so far i'm quite enjoying it
[04:59:22] BuildTheRobots: not sure if you've seen http://adventofcode.com/2017 or not. last year I found it substantially harder compared to this year armed with nothing but a third of a ruby tutorial ;)
[05:12:03] BuildTheRobots: hmm, is there a fuzzy equivalent of include? eg so it returns true: a=["foobar"]; a.include? 'foo'
[05:14:38] baweaver: The top functions you want to know by heart in Ruby for Enumerable are: map, select, find, and reduce
[05:15:11] baweaver: select is the one you'd normally want to use, but it turns out there's another one that's even more applicable in this specific case
[05:23:32] BuildTheRobots: i'm using a regex or trying to, but having issues using a variable _between_ the slashes, so as part of the match condition
[05:26:17] BuildTheRobots: i have the same problems using grep, can't use a vaeriable as the match term
[05:28:01] BuildTheRobots: hmm, same problem. so how do I use dynamic data as the match term in a regx?
[05:31:49] ruby[bot]: BuildTheRobots: # => undefined local variable or method `success' for main:Object (NameError) ...check link for more (https://eval.in/915725)
[05:32:28] BuildTheRobots: b should not print success, (the second attempt) the string boo does not apear
[05:34:14] BuildTheRobots: ok, so at the end of all that, i think i learn that i can't use a regex match in an if statement
[05:34:52] BuildTheRobots: so going back to the start, how can i do an `if (fuzzymatch variable against array == success) do something
[05:48:27] RickHull: what's a good approach for converting yaml into a class? or alternatively converting a class definition to yaml? just constants/data
[05:49:06] RickHull: https://github.com/rickhull/traveller_rpg/blob/master/lib/traveller_rpg/careers.rb
[05:49:37] RickHull: so I have Agent < Career. i want to put Agent: as a top level key in careers.yaml
[05:52:16] RickHull: well, I don't care about serialization. but i want to declare different careers in YAML rather than ruby classes
[05:56:12] RickHull: so right now, Agent < Career. but I could ostensibly do: agent = Career.new(stuff: that, used: to, be: class, constants: etc)
[12:41:04] dminuoso: porfavordama: Because having too many methods doing the exact same thing is bad.
[12:46:43] Papierkorb: porfavordama: If you can, upgrade to 2.4 - If you can't, if all you need is String#match?, it's easy to implement it yourself. I'm sure there's also a backport gem which does stuff like this, but can't remember its name.
[12:48:40] porfavordama: Papierkorb: Yes, all I am looking for is to match a certain pattern from a text. :) If I can't upgrade then I will figure out somehow. Thank you for the help :)
[13:06:33] Papierkorb: porfavordama: While I like match? more simply because it's a method, the only semantic difference between match? and match/=~ is that match? doesn't set the $~ and $1,$2,.. fake globals
[13:08:33] porfavordama: Papierkorb: Yes, I just needed the truthy. So, also include? could be the answer.
[13:09:20] Papierkorb: porfavordama: #include? only works for strings. If that's good enough for you, it's what I'd use
[16:24:54] leitz: It came in the mail Tuesday but I couldn't open it until the class I'm in was done. Which it now is.
[16:25:42] leitz: I thihnk my brain will melt but the book should help me with my Character Generator.
[18:53:12] leitz: impermanence, I tend to look at how gems are laid out. There's a command to build the tree but I can't remember it.
[19:02:51] dminuoso: I've seen so many different layouts, and I had never problem navigating "strange" and "new" concepts each time.
[19:03:32] impermanence: dminuoso: true dat. I mean, like, java has some norms'n'forms so...sjust curious.
[19:04:17] dminuoso: impermanence: I found that adhering to specific layouts can be constraining. In our react app for example it took a bit of experimentation what works for us because all the "popular" schemes just felt wrong/
[19:05:13] dminuoso: impermanence: Even in our rails app I started breaking common convention because the traditional rails way feels wrong for us.
[19:07:05] leitz: dminuoso, I think the key is "feels wrong". As a newbie I prefer to stick with the standard. Later, maybe, I'll have enough experience to break the rule when it is good to.
[19:08:21] dminuoso: leitz: I agree. I didn't consider it with Rails until we demystified Rails. Now we just treat it as a ruby application.
[19:09:56] dminuoso: It might be useful to look at similar projects and orient yourself using their structure to get started.
[19:10:51] impermanence: dminuoso: a process monitor that reads from /proc/ and writes to ncurses or something similar.
[19:12:06] impermanence: yeah and this morning I was all like...wait...maybe I just have a test dir, lib dir, bin dir, etc...but didn't know if there were forms
[19:13:42] dminuoso: impermanence: also note if you are using `rspec` then test/ is usually called spec/
[19:14:28] impermanence: dminuoso: hm. I was putting my minitests in there...I'm...new to ruby testing, lol
[19:14:59] leitz: It unpacks the gem into the directory. You can see how it's done by others. json is an example.
[19:15:23] dminuoso: impermanence: With unit testing it makes sense that if you have some api.js that you should also have an api.test.js :-)
[19:15:44] dminuoso: and it makes absolute sense they should be sitting next to each other. it also makes things like relative file access more sensible..
[19:17:45] impermanence: dminuoso: I'm new to minitest too but spec functionality makes up about a third of its purpose
[19:19:23] dminuoso: impermanence: rspec is just a name, it has it all. Anyway, not trying to swing you over - it's just that I cant speak for minitest =)
[19:21:02] impermanence: leitz: I'm a total ruby newb, but I find that when I write actual applications it makes me better, thas all. I am beginning to know *nix fairly well and I was recently looking at process mon tools so I figured I'd just write my own. nuffin special.
[19:23:35] leitz: Ruby is, for me, the most fun. It calls me to code. I can do more in bash and some with PHP, Python, or even a little C or Go. However, Ruby is the only one that really encourages me to code.
[19:24:27] leitz: As a newbie, I recommend staying with the "standard". At least for a while. People like dminuoso know a heck of a lot more Ruby than I do, and they can step outside the standards when it's best for them.
[19:27:12] leitz: The spec.helper confused me when I started with rspec. Never really got it then wandered away for a bit. Using test/unit
[19:29:02] dminuoso: leitz: spec_helper.rb is just the initialization file. `rspec_config.rb` would have been better
[19:29:47] dminuoso: Especially in rails when you also have a rails_helper.rb its even more confusing..
[19:55:18] leitz: Acutally, I think I need to figure out how to make it a gem. That will push me to standardize a bit more.