#ruby - 18 June 2018
« Back 1 day Forward 1 day »
[03:06:53] wadadli: so I used bundler to install bootstrap, to use it I just add @import at the top of a .css file?
[04:22:52] darkworld: I know C, and I don't want to touch Python with a billion foot pole because of whitespace syntax
[04:27:23] baweaver: Though the fact that you entered with the predefined assumption that it's a hipster language, it sounds like you already have an answer.
[04:28:00] darkworld: the only people ive ever met who used ruby have been hipsters but honestly anything is better than python so im actually curious if its good for general purpose use or not
[04:29:32] baweaver: By coming in from an actively hostile position (they're all hipsters) you do both yourself and the language a disservice.
[13:33:30] catphish: is there such thing as an ssh agent (key server) for ruby net/ssh, i couldn't find anything
[13:34:07] catphish: i need to be able to do 2 ssh hops and was hoping to forward keys, but can't figure it out
[14:41:09] catphish: seems a pretty effective way to authenticated between a series of trusted hosts
[14:42:45] catphish: cdunklau: sadly that won't work, i'm trying to automate some backups, having a management server connect to one server, then rsync to a third server
[14:43:07] catphish: i can fix this my manually generating unique keys on every server and configuring trust as necessary
[14:44:38] cdunklau: catphish: ":forward_agent => set to true if you want the SSH agent connection to be forwarded"
[14:44:41] catphish: i want to have a management server connect to one server, then rsync to a third server for backup purposes
[14:45:26] catphish: cdunklau: i believe that will forward agent connections, but i'm not really sure what it would forward them to, my key only exists in ruby
[14:46:32] catphish: i suspect what i'll end up doing instead is just automating the configuration of private keys on each server and distribution of the public keys as needed
[14:46:59] catphish: cdunklau: that's not a bad idea actually, as long as i can spawn a unique agent for this purpose, and somehow forward to it
[14:49:47] catphish: i have an existing management system that connects to several servers and manages them in various ways, and now i want to be able to create an ssh connection *between* 2 of those servers
[14:53:51] catphish: for a start, the private key includes the public key, or the information needed to generate it
[14:56:20] cdunklau: catphish: so yeah i think this will work: you run ssh-agent -s, parse out the env vars, set them in your program's environment, run ssh-add - and give it the key, then you should be good
[14:57:55] cdunklau: catphish: confirm this, but presumably net/ssh will look in the environment to get the agent info
[14:59:23] catphish: looks like that might work, just need to make sure i don't spawn lots unnecessarily
[15:00:30] cdunklau: catphish: oh it looks like you can tell ssh-agent what address to use for its domain socket
[15:01:24] catphish: the app can just start it the first time it's needed then check the socket is available
[15:05:27] catphish: i have an existing management system that connects to several servers and manages them in various ways, and now i want to be able to create an ssh connection *between* 2 of those servers
[15:06:48] cdunklau: catphish: i'd probably do this via the backup server, and just have the management server tell the backup server to do it
[15:08:26] cdunklau: i mean you have to have comms between the target server and the backup server, of course, but do you really want the whole thing to *also* depend on the management server <-> target server connection?
[15:08:59] cdunklau: that just seems brittle, especially for a presumably long-running thing like backup
[15:09:08] catphish: but there are several backup servers, and servers can be provisioned at any time, so having a separate private key on each management server and adding that to all the other servers seemed like an unwanted step, when the management server can just authorize each action
[15:10:12] cdunklau: catphish: either way is the same number of hosts, sure, but my suggestion doesn't rely on all three of them communicating properly for the whole process
[15:12:21] catphish: it would be cool to have a daemon on the backup server that is asked to do a backup, and monitors the success, then the management server could just check on progress
[15:12:35] catphish: but that's rather more complicated than just running one ssh command and watching the output
[15:13:01] catphish: and these backups are quite small, not like whole system backups, just shared hosting sites
[15:41:13] jrich523: hey guys, is there any difference between the top and bottom? https://gist.github.com/jrich523/1eb7bc425367ded87278542ba76e7156
[15:41:34] jrich523: the top is the way it was written, the bottom is what i figured it can/should be?
[17:05:14] jrich523: so if i need a method that i can call with arguments or no arguments, what is the ideal way to do that? just check for nil params?
[17:12:37] z64: omitting arguments is done by giving args default values, i.e. `def foo(arg = nil)` can be called as `foo` or `foo(something)`
[17:15:55] z64: sure. definitely think about it in each situation; sometimes a more explicit, differently named method is preferred. for your use case that sounds fine
[17:29:02] guns: Hello. Are the "# encoding: utf-8" magic comments still a good idea in Ruby 2.5 for source files with UTF-8 characters?
[17:58:45] Inside: It was even better when passenger was serving up one application in a 2.1.4 environment and 2.4.0 in the other
[18:00:40] SeepingN: all of the networking/ssh/sftp stuff changed so much that there was much pain and confusion
[18:01:01] Inside: if you just write idiomatic ruby code without using a single library or fancy language feature -- your code is forever future compatible <3
[18:01:08] SeepingN: the ways it reported failures, or now reported failures where before it just bombed out... ugh. Good changes, but ugly transition
[18:01:41] cthulchu: I mean, if you use Assembly to write code, Ruby updates won't affect it either :)
[18:13:52] wadadli: @import "../../vendor/bundle/ruby/2.5.0/gems/bootstrap-4.1.1/assets/stylesheets/_bootstrap.scss";
[18:20:06] cthulchu: so not having spaces between parenthesis and metod names applies to when we define them too?
[18:21:34] wadadli: bundler is configured to install it's deps locally in the ` vendor/bundle/ ` dir
[18:22:26] wadadli: I'm not sure if it has that functionality either since it isn't mentioned in the docs.
[18:23:23] wadadli: now I'm not a ruby guy by any means and I'm just using this framework and the dep tracker that they recommend it's just a pitty that it can't do simple things like that
[18:24:01] wadadli: so what's the next move, install another dep tracker alongside your existing dep tracker to do this sort of thing? o_
[18:34:19] ruby[bot]: cthulchu: # => /tmp/execpad-df079005e7ad/source-df079005e7ad:2: class/module name must be CONSTANT ...check link for more (https://eval.in/1022853)
[18:35:14] ruby[bot]: cthulchu: # => /tmp/execpad-27df3b422290/source-27df3b422290:2: syntax error, unexpected tIDENTIFIER, expecting key ...check link for more (https://eval.in/1022856)
[18:39:26] ruby[bot]: cthulchu: # => /tmp/execpad-2a44538bc8a5/source-2a44538bc8a5:2: warning: class variable access from toplevel ...check link for more (https://eval.in/1022867)
[18:42:28] cthulchu: what's wrong about it? @@ is the class-scope variable. Once the class is there, I should be able to access all its.... static variables.
[18:49:08] cthulchu: >>class Test; @@qwe=123; def self.getQwe; return @@qwe; end; end; puts Test.getQwe()
[18:49:39] dminuoso: cthulchu: On the basis that class variables are almost always wrong, Im gonna go with: No.
[18:49:42] cthulchu: I think self.method is a very weird construct but I guess it works because classes are objects
[18:50:24] dminuoso: cthulchu: `def foo.bar; ...; end` defines a method :bar on the singleton class of whatever `foo` is.
[18:50:28] baweaver: Though I'd still argue that reading through a book like Eloquent Ruby would be good at this point.
[18:50:34] dminuoso: cthulchu: Inside the class definition `self` happens to be that class object itself.
[18:50:38] cthulchu: okay, say you have a dogs class. you want to store in it the max height and weight od a dog.
[19:44:41] havenwood: cthulchu: In Ruby, if you have no instances of internal state, use a module. Modules are the one place that the docs refer to "functions" rather than "methods," with `module_function`.
[19:46:07] cthulchu: a class of dogs, but I want to set the nubmer of tails for all dogs in this class
[19:46:30] andrewray: Hello. I feel frustrated writing ruby, because the adopted design patterns are all pseudo-OO, when it seems like only using functions/lambdas is possible, but not explored
[19:46:55] havenwood: andrewray: Many folk these days do prefer to write Ruby in a functional fashion. I like it.
[19:46:56] andrewray: are there any articles or mentalities that explore a non-OO approach to ruby, like other dynamic languages have adopted? Or should I give up my dream and acknowledge that OO is the "ruby way"
[19:47:17] havenwood: andrewray: The folk behind tools like the Dry gems, ROM and Roda are big into functional programming.
[19:47:36] cthulchu: I would actually enjoy functional approach in Ruby too if I hadn't have the legacy of oop
[19:47:59] andrewray: havenwood: hmm, the first example dry gem http://dry-rb.org/gems/dry-auto_inject/ is a class mixin, and I want to avoid both classes and mixins :P
[19:48:33] havenwood: andrewray: They're trying to be good functional citizens in an OO world. Yeah, it's not pure functional.
[19:48:48] andrewray: but I also want a thinkpiece on if this is possible and scalable in ruby. there's some fundamental issues with the language that I suspect would make it difficult, but I don't have enough experience to make a judgement call
[19:49:14] andrewray: havenwood: understood, I'm not aiming for pure FP (and don't have any pure fp experience)
[19:49:14] havenwood: andrewray: Lack of immutable data structures, pattern matching and TCO are limitation that come to mind.
[19:49:17] cthulchu: okay, let's say I have a dog class with many dog instances. I want to know how many dogs I have. For this, I need a static class variable and I need to increment it by one in the constructor. How do I create that variable?
[19:49:49] havenwood: andrewray: There are libraries for immutable data structures, like Hamster. I think we might just be better off using JRuby with Clojure data structures. ;-P
[19:50:17] havenwood: andrewray: There's a fork of Ruby with pattern matching that was presented at Ruby Kaigi. I think it'll be in Ruby's future.
[19:50:43] havenwood: andrewray: You can currently enable TCO, but it's disabled by default in favor of trace instructions.
[19:50:50] andrewray: this question is also specific to a rails ecosystem, where i'm also wondering if I can do anything to structure the app that's not class-hard-baked 24/7. it's already difficult because models are central to everything
[19:51:34] havenwood: cthulchu: You could use a Singleton class to count dogs. You could use class variables. Maybe even the observer pattern.
[19:51:53] andrewray: I don't have immutable data, I have a "thing" that knows how to update itself, what its connected to, how to manipulate and mutate itself, and I'm frustrated that the design patterns around models don't consider making a model just data
[19:52:20] dminuoso: andrewray: they provide a different mental model to structure apps, it's slightly more FP inclined.
[19:52:23] havenwood: andrewray: +1 trailblazer - even if it's just for ideas and you don't use the lib
[19:53:40] havenwood: cthulchu: Do you always care about all dog tails, or some dog's tails don't count?
[19:56:09] andrewray: thank you havenwood and dminuoso this is something to explore. i'm still unclear if I can write closer-to-explicit-functions-everywhere especially in a rails ecosystem, or if I should bolster on an anti-class mentality wherever I can, and acknowledge that there are some things I can't change
[20:20:48] havenwood: cthulchu: Here's a contrived example of a TailCounter Singleton Class, just to show a few things: https://gist.github.com/havenwood/936c64ae9fae91f18450bf1d3754a12e
[20:25:06] havenwood: cthulchu: https://ruby-doc.org/stdlib-2.5.0/libdoc/observer/rdoc/Observable.html
[20:28:53] havenwood: cthulchu: You might try a stab at the Observer pattern with a Singleton class counter, as an exercise.
[20:29:45] havenwood: Extra points for implementing your own serialization on the singleton class, with an option to dump or load the counter from disk.
[20:36:14] havenwood: zenspider: It's certainly not the simplest thing that possibly works, but cthulchu wants the most complicated thing that possibly works I think. ;-P
[20:37:18] zenspider: I'd probably throw a const w/ an array in the main class, add the instance to the collection, and then enumerate that to sum the tails.
[20:42:23] cthulchu: It's a bit weird that the concept of a static variable is so disturbing in Ruby
[20:43:21] cthulchu: I just realized how to implement what I want via static setters/getters and you give me something completely different and a lot more complex
[20:53:03] havenwood: cthulchu: I think you'll have better luck accomplishing tasks without trying to use the Java analogue to do so. Try the simplest thing that can possibly work, without paying attention to how Java does it.
[20:53:52] cthulchu: I have analytics test instance that gets created in a test and runs instance methods to check analytics stuff
[20:54:01] TvL2386: I've been programming Ruby for 10 years now. I am a network guy, so don't listen to me, but a "static class var" is not something that lands
[20:54:27] cthulchu: after each analytics test, I want to have a global variable in my class to push the results in it.
[20:57:01] TvL2386: maybe you can make an object to contain your analytic test data and pass that to your test instance to accumulate the results?
[20:57:35] elomatreb: I have never seen a situation where a class var was the right tool for the job, and not a red herring
[20:57:50] Lyfe_: I don't know why you would store a value into any sort of shared state prior to printing it, since that sounds like a future race condition issue to me.
[20:58:28] TvL2386: probably if I grep through my code `grep -r @@` of the last ten years I'll get a handful of hits
[20:58:40] zenspider: a class constant or class ivar or even a class cvar are vastly better than a global
[20:58:58] havenwood: cthulchu: Where does this inter-instance, accumlated info get ultimately used?
[20:59:52] TvL2386: yeah if you wanted a static class variable, you could still use a class constant
[20:59:55] havenwood: cthulchu: Are you accumulating these stats to print them at the end of the tests? Or something else?
[21:01:03] havenwood: I wonder if it'd be nicer to freeze constants by default. I can't recall the last time I used a constant without it being frozen.
[21:03:10] havenwood: cthulchu: There's not a straightforward way to thaw something that's frozen, other than #dup. It's of course possible with Fiddle. >.>
[21:03:59] elomatreb: And freezing is not recursive either, so e.g. if you freeze a Hash you can't insert new keys but you can mutate the members that are already there
[21:04:02] havenwood: cthulchu: Constants are not frozen by default. They give you a warning if you reassign the value, but not if you mutate it.
[21:05:26] havenwood: elomatreb: there have been a few issues around it - i vaguely recall something promising
[21:05:51] TvL2386: I just knew from years ago ruby gave a warning when reassigning... haven't don't it for ages... not exactly a good practice so I was wondering how 2.6.0-preview2 would react
[21:21:35] TvL2386: so... I'm having a problem I'm trying to solve.... I made a multi user website where you can track your amount and value of "assets". Every hour my site gets updated from an external source so I know the most recent values for all assets. So far so good... But now I wanted history information, so I added a table where I keep track of the history. Problem is that all those data points are too much and I
[21:23:02] havenwood: TvL2386: I think we have a lot of DB baggage from the days where we had no space, so everything had to be optimized towards space-saving.
[21:23:26] havenwood: TvL2386: DBs like Datomic make a lot of sense. It's a shame they don't yet have more mindshare.
[21:24:42] TvL2386: I'll check that out havenwood! Never heard of it... I was thinking to look at influxdb
[21:24:58] havenwood: TvL2386: Rich Hickey has a good talk discussing how facts change over time, and that's what we care about: https://www.youtube.com/watch?v=V6DKjEbdYos
[21:26:05] elomatreb: Do you actually need the full history though? The simplest solution that would avoid the need of moving databases would be a cronjob that cleans the history, say, to a million points
[21:27:03] havenwood: TvL2386: Datomic can actually use MySQL (I presume MariaDB as well) for the storage service.
[21:27:26] havenwood: TvL2386: If you need to query against facts over time, it might be worth looking at.
[21:28:38] TvL2386: elomatreb: I have a routine to delete points for records older than a certain date, that helps
[21:29:28] elomatreb: Yeah, combined with a proper index I don't really see why you should want to involve super-fancy custom databases
[21:29:38] TvL2386: also my highchart multiline graphs really don't like multiple lines containing several megabytes of json data
[21:34:21] TvL2386: I'm also thinking that instead of saving everybodies "amount and value of ITEM" every hour, it maybe better to just save "value of 1 ITEM" every hour and only save everybodies amount when it changes. Then correlate the two
[22:16:38] LongcatLulz: I made an indie exploration game in my spare time: https://socah.itch.io/railroadtracks
[22:28:18] WhereIsMySpoon__: has left #ruby: ("http://quassel-irc.org - Chat comfortably. Anywhere.")