« Back to channel list

#ruby - 08 August 2019

« Back 1 day Forward 1 day »
[00:07:33] AJA4351: has joined #ruby
[00:25:20] drincruz: has joined #ruby
[00:34:01] k0mpa: has joined #ruby
[00:34:09] sytherax: has joined #ruby
[00:36:21] morenoh149: has joined #ruby
[00:44:13] k0mpa: has joined #ruby
[00:48:40] jenrzzz: has joined #ruby
[00:50:06] txdv: has joined #ruby
[01:15:44] x86sk: has joined #ruby
[01:18:05] AJA4350: has joined #ruby
[01:19:38] meinside: has joined #ruby
[01:23:20] bmurt: has joined #ruby
[01:28:34] drincruz: has joined #ruby
[01:30:31] morenoh149: has joined #ruby
[01:40:21] bambanx: has joined #ruby
[01:42:43] evdubs_: has joined #ruby
[01:42:58] ukd1: has joined #ruby
[01:50:27] morenoh149: has joined #ruby
[01:51:13] sagax_: has joined #ruby
[01:55:20] hutch: has joined #ruby
[01:59:21] jenrzzz: has joined #ruby
[02:03:51] kacykurio: has joined #ruby
[02:11:02] greengriminal: has joined #ruby
[02:26:09] skryking: has joined #ruby
[02:35:07] sytherax: has joined #ruby
[02:42:53] duderonomy: has joined #ruby
[03:08:25] qbrd[m]: When in doubt try it again while cursing under your breath...
[03:15:12] _whitelogger: has joined #ruby
[03:23:41] fredolinhares: has joined #ruby
[03:24:00] SanguineAnomaly: has joined #ruby
[03:36:33] h1r0P0p18: has joined #ruby
[03:40:44] jmcgnh: has joined #ruby
[03:45:27] code_zombie: has joined #ruby
[03:47:29] duderonomy: has joined #ruby
[03:47:32] jmcgnh: has joined #ruby
[04:04:17] howdoi: has joined #ruby
[04:14:40] duderonomy: has joined #ruby
[04:33:28] code_zombie: has joined #ruby
[04:40:30] jenrzzz: has joined #ruby
[04:58:14] Mrgoose8: has joined #ruby
[05:02:32] morenoh149: has joined #ruby
[05:03:58] ur5us: has joined #ruby
[05:06:17] donofrio: has joined #ruby
[05:06:29] tsujp: has joined #ruby
[05:20:52] Mrgoose8: has joined #ruby
[05:25:44] ascarter: has joined #ruby
[05:30:17] duderonomy: has joined #ruby
[05:50:30] glosoli: has joined #ruby
[05:53:01] duderonomy: has joined #ruby
[05:55:58] jenrzzz: has joined #ruby
[05:58:48] fphilipe_: has joined #ruby
[06:03:25] dellavg: has joined #ruby
[06:09:32] za1b1tsu: has joined #ruby
[06:18:36] glosoli: has joined #ruby
[06:28:00] ramfjord: has joined #ruby
[06:36:45] sytherax: has joined #ruby
[06:39:44] za1b1tsu: has joined #ruby
[06:43:29] lxsameer: has joined #ruby
[06:49:29] al2o3-cr: &>> require 'fiddle'; Fiddle::Pointer[TrueClass.__id__ * 2][0,64] = Fiddle::Pointer[FalseClass.__id__ * 2][0,64]; [false == false, true == true, 0 == 0]
[06:49:32] rubydoc: # => [false, false, false] (https://carc.in/#/r/7dcu)
[06:49:43] Sylario: has joined #ruby
[06:49:55] al2o3-cr: just how much fun can we have with this today ;)
[06:55:07] fphilipe_: has joined #ruby
[06:56:09] duderonomy: has joined #ruby
[06:56:24] TomyWork: has joined #ruby
[06:57:08] za1b1tsu_: has joined #ruby
[06:59:19] al2o3-cr: &>> require 'fiddle'; include Fiddle; sc = Function.new Handle['sincos'], [TYPE_DOUBLE, *[TYPE_VOIDP] * 2], TYPE_VOID; s = [0].pack ?d; c = [0].pack ?d; sc.(34.5, s, c); [s,c].map { |v| v.unpack1 ?d }
[06:59:20] rubydoc: # => [0.057487478104924564, -0.9983462274487422] (https://carc.in/#/r/7dd0)
[07:00:14] corellian: has joined #ruby
[07:03:03] glosoli: has joined #ruby
[07:16:26] deepredsky: has joined #ruby
[07:17:01] aupadhye: has joined #ruby
[07:23:37] Nicmavr: has joined #ruby
[07:43:04] kyrylo: has joined #ruby
[07:52:54] duderonomy: has joined #ruby
[08:02:57] gigetoo: has joined #ruby
[08:08:15] za1b1tsu_: has joined #ruby
[08:15:47] morenoh149: has joined #ruby
[08:25:41] mikecmpbll: has joined #ruby
[08:30:09] bruce_lee: has joined #ruby
[08:30:10] bruce_lee: has joined #ruby
[08:31:39] mat_bug: has joined #ruby
[08:35:04] fphilipe_: has joined #ruby
[08:51:04] lalitmee: has joined #ruby
[09:10:24] morenoh149: has joined #ruby
[09:13:35] howdoi: has joined #ruby
[09:15:51] leitz: has joined #ruby
[09:24:11] _whitelogger: has joined #ruby
[09:27:10] deepredsky: has joined #ruby
[09:31:17] drnerdius: has joined #ruby
[09:32:29] kyrylo: has joined #ruby
[09:37:00] kyrylo: has joined #ruby
[09:39:37] kyrylo: has joined #ruby
[09:44:54] leitz: Lines 66-68 are the catch for hitting EOF with data. Is there a way to put that in the block above? https://github.com/LeamHall/resume/blob/master/bin/parse_jobs.rb#L66-L68
[09:51:17] drnerdius: has joined #ruby
[09:56:55] RougeRR: has joined #ruby
[09:57:17] RougeRR: hello, i need some assistance with open3, anyone got experience?
[09:58:54] mat_bug_: has joined #ruby
[09:59:21] RougeRR: this is the code im working with https://dpaste.de/j438
[10:00:37] RougeRR: when reading a file with large amounts of stderror/stdout
[10:00:52] RougeRR: and i know its to do with the buffer being overwhelmed
[10:01:47] deepredsky: has joined #ruby
[10:08:03] leitz: RougeRR, what is the output if you just run the command?
[10:08:24] RougeRR: leitz, i get a huge amount of output to stderror
[10:08:37] RougeRR: and stdout
[10:08:46] RougeRR: its a bit of edge case behaviour
[10:09:03] RougeRR: i cant provide the source im working with unfortunately as its sensitive
[10:09:21] leitz: Understood on the "sensitive".
[10:09:49] leitz: Is stdout and stderr line based? That is, could you read it a line at a time?
[10:09:56] RougeRR: that is a thought ive had
[10:10:03] RougeRR: seems you would want to buffer it
[10:10:06] RougeRR: ill give that a go
[10:10:13] RougeRR: i tried spawning each one in a new thread
[10:10:27] RougeRR: but it didnt seem to do work
[10:10:56] leitz: It will likely hit IO heavy, but it might let you filter as you go, if you don't need all of it.
[10:11:58] RougeRR: i dont need msot of it no
[10:12:06] RougeRR: its mostly noise that isnt going to be needed for the program
[10:12:12] leitz: Do you really need an object for this?
[10:13:42] involans: has joined #ruby
[10:15:09] deepredsky: has joined #ruby
[10:16:48] havenwood: RougeRR: lines 21 and 23 are a good case for a lonely person operator: stdout&.read
[10:18:11] RougeRR: havenwood, but they arnt causing exceptions by stdout being nil?
[10:18:23] RougeRR: leitz, i should mention. this is not my code.
[10:18:31] RougeRR: im trying to fix a gem which im using
[10:18:37] havenwood: &>> nil&.read
[10:18:39] rubydoc: # => nil (https://carc.in/#/r/7dee)
[10:19:44] RougeRR: https://stackoverflow.com/questions/1154846/continuously-read-from-stdout-of-external-process-in-ruby
[10:19:48] RougeRR: seems like my same issue
[10:19:51] leitz: ACTION wonders what havenwood is doing up this late.
[10:21:06] havenwood: leitz: Can shorten line 4 a bit now that there's __dir__: $LOAD_PATH << File.expand_path('../lib/', __dir__)
[10:21:58] havenwood: leitz: Not that it matters here, since the process ending closes the file descriptor, but the block form of File.open auto-closes on end.
[10:22:21] kyrylo: has joined #ruby
[10:22:23] havenwood: leitz: it's faster to parse Array literal `[]` instead of Array.new.
[10:23:10] leitz: havenwood, I've used the block for now and again. This is proof of concept for me, I've been stumped on how to parse the file for a long time. And it seems having a current resume is good. :)
[10:23:26] havenwood: leitz: Normally I'd suggest extracting your Regexp to a constant. Creating it in a method causes object churn.
[10:24:17] leitz: I tend to use "Array.new" or Hash.new so I can search for it in the files. Unix grep often chokes on special character strings like []
[10:24:31] havenwood: leitz: I'd recommend replacing `return start_date, end_date` with: [start_date, end_date]
[10:24:48] leitz: And I'm newbie enough to have to find how I figured something out before. :)
[10:25:57] havenwood: leitz: I'd probably one-line the if statements, like: return date if dates[0] == "present"
[10:26:15] havenwood: leitz: #size to me signals a lazily calculated size, where #count often actually iterates to count.
[10:26:41] RougeRR: found a solution
[10:26:42] havenwood: leitz: you can put `year =` outside the if statement, and only do it once
[10:26:47] RougeRR: https://stackoverflow.com/questions/1154846/continuously-read-from-stdout-of-external-process-in-ruby
[10:26:54] RougeRR: im just working out how it works and why now
[10:27:11] havenwood: leitz: I like: data.positive?
[10:28:23] ramfjord: has joined #ruby
[10:30:08] Fraeon: has joined #ruby
[10:32:13] drincruz: has joined #ruby
[10:33:05] leitz: havenwood, is there a better solution for lines 66-68? They are there to catch the last job in the file.
[10:33:41] leitz: ACTION has to makes notes. When the "get to work" chime rings he has to magically transform into a perl guy. :(
[10:36:04] leitz: RougeRR, have you figured out how that works?
[10:36:30] deepredsky: has joined #ruby
[10:36:39] RougeRR: leitz, so its to do with STDOUT not flushing the bugger
[10:37:34] RougeRR: if the process is being called from another process
[10:37:40] RougeRR: rather than the shell
[10:37:47] RougeRR: then this buffer is never sent
[10:37:56] RougeRR: so by using a psuedoterminal, we can work around this.
[10:38:35] RougeRR: by emulating a shell within the program, the stdout stream is sent in real time
[10:38:41] RougeRR: rather than buffering and never being sent
[10:38:54] RougeRR: that was poorly explained. the stackoverflow answer says it better
[10:41:13] leitz: An unflushed buffer can be a bugger. :)
[10:44:10] nerdius: has joined #ruby
[10:45:58] jackholmes: has joined #ruby
[10:47:16] jackholmes: has left #ruby: ()
[10:49:09] AJA4350: has joined #ruby
[10:53:18] drnerdius: has joined #ruby
[10:55:57] tuor: has joined #ruby
[11:08:37] RougeRR: another method ive found works
[11:09:19] RougeRR: https://dpaste.de/eOjN
[11:09:29] RougeRR: i think the issue is popen3
[11:09:33] RougeRR: as that spawns a new process
[11:10:12] jenrzzz: has joined #ruby
[11:10:46] drnerdius: has joined #ruby
[11:17:00] tsujp: has joined #ruby
[11:18:09] ellcs: has joined #ruby
[11:20:49] leitz: RougeRR, I'm mostly a Ruby newbie, and not as familiar with the Ruby process stuff. Glad that you're enjoying figuring it out!
[11:25:07] RougeRR: Yeah, been using ruby 2 years. Still a noob at any other language/programming stuff.
[11:25:16] RougeRR: nice to learn process stuff etc yeah
[11:33:40] deepredsky: has joined #ruby
[11:42:11] tsujp: has joined #ruby
[11:44:34] jenrzzz: has joined #ruby
[11:46:46] basic: has joined #ruby
[11:47:28] basic: how does one tell rubocop to parse like it's 2017 (ruby 2.5)
[11:48:41] havenwood: basic: TargetRubyVersion: 2.5
[11:48:48] mat_bug: has joined #ruby
[11:52:23] kyrylo: has joined #ruby
[11:57:04] basic: havenwood: does rubocop try to find this configuration file?
[11:57:15] basic: like inside the filetree strcutre
[11:57:31] basic: wow, compiling ruby is quick
[11:58:08] basic: which would be my next question, do i need ruby 2.5+ installed for rubocop to work? or does it use it's parsers?
[11:58:15] kyrylo: has joined #ruby
[11:58:40] havenwood: basic: you can use whatever version of Ruby you want
[11:58:53] havenwood: basic: Ruby 2.6.3 is the latest version.
[11:59:02] havenwood: basic: https://docs.rubocop.org/en/stable/configuration/
[11:59:08] basic: hm, doesn't seem to work
[11:59:29] havenwood: basic: what doesn't work
[11:59:41] basic: i have the config file in the root directory of the project
[11:59:55] havenwood: what seems to be the problem?
[12:00:06] basic: and rescue blocks (implicit begin...end) that will be shown as errors on my linter
[12:00:10] basic: (i use ALE for vim)
[12:00:22] basic: does that maybe ignore the rubocop config?
[12:00:39] havenwood: ¯\_(ツ)_/¯
[12:01:31] basic: undefined method `[]' for 2.5:Float
[12:01:47] basic: (if i call rubocop manually)
[12:02:02] basic: do i have to specify it as string?
[12:03:29] havenwood: basic: Without knowing what you've done, it's hard to say.
[12:03:30] havenwood: basic: Here's an example .rubocop.yml: https://github.com/rubocop-hq/rubocop/blob/master/.rubocop.yml
[12:03:36] basic: Warning: unrecognized cop TargetRubyVersion found in .rubocop.yml
[12:03:55] havenwood: basic: If you share your config, and the command you're running, I'm sure someone here can point out what's gone wrong.
[12:04:06] basic: ah, i get it, one sec
[12:04:24] kyrylo: has joined #ruby
[12:04:36] basic: holy shit rubocop hates my code
[12:04:49] havenwood: basic: have it fix it: rubocop -a
[12:05:40] basic: well it's still doing 2.3
[12:05:59] basic: http://dpaste.com/3PCNKAX
[12:06:23] havenwood: basic: what version is your Ruby?: ruby -v
[12:06:39] basic: it's 2.4 right now
[12:06:51] basic: 2.4.6 to be exact
[12:06:57] havenwood: basic: do you have RuboCop installed on the current version of Ruby?: gem which rubocop
[12:07:01] basic: but my project runs in docker, which is 2.5.3
[12:07:06] basic: i only have that ruby version
[12:07:28] havenwood: basic: If the project runs on 2.5, I'd suggest using 2.5 locally
[12:07:51] havenwood: basic: it's common for Ruby developers to install many versions of Ruby, and switch between them for various projects
[12:08:03] basic: havenwood: poor fools
[12:08:07] havenwood: basic: what OS/distro are you on locally?
[12:08:40] havenwood: https://gpo.zugaina.org/dev-ruby/chruby
[12:09:35] havenwood: basic: it looks like there's a portage package for Ruby 2.5
[12:09:46] basic: yeah i installed 2.6 right now
[12:17:22] basic: hm, looks like ALE uses the installed ruby version not rubocop at all
[12:17:59] kyrylo: has joined #ruby
[12:21:37] basic: ACTION wonders how it uses ruby as integrated linter
[12:22:23] stryek: has joined #ruby
[12:28:39] mat_bug: has joined #ruby
[12:28:52] GodFather: has joined #ruby
[12:28:57] GodFather_: has joined #ruby
[12:41:07] mat_bug_: has joined #ruby
[12:48:13] sytherax: has joined #ruby
[12:53:21] jenrzzz: has joined #ruby
[12:58:51] deepredsky: has joined #ruby
[13:01:06] mat_bug: has joined #ruby
[13:03:35] AJA4350: has joined #ruby
[13:08:55] drnerdius: has joined #ruby
[13:10:24] lucasb: has joined #ruby
[13:13:50] chalkmonster: has joined #ruby
[13:16:38] drincruz: has joined #ruby
[13:18:59] poontangmessiah: has joined #ruby
[13:20:41] Swyper: has joined #ruby
[13:22:00] h1r0P0p18: has joined #ruby
[13:22:57] leitz: has joined #ruby
[13:26:00] greengriminal: has joined #ruby
[13:33:03] bmurt: has joined #ruby
[13:33:42] snapcase: has joined #ruby
[13:54:51] jenrzzz: has joined #ruby
[14:00:52] lalitmee: has joined #ruby
[14:02:49] hutch: has joined #ruby
[14:11:53] kyrylo: has joined #ruby
[14:13:14] kyrylo: has joined #ruby
[14:15:37] redlegion: has joined #ruby
[14:16:17] duderonomy: has joined #ruby
[14:18:25] tdy: has joined #ruby
[14:23:39] drnerdius: has joined #ruby
[14:36:36] wallace_mu: has joined #ruby
[14:41:43] havenwood: If Perl 6 is renaming to "Camelia," does that mean Ruby 3 is free to rename to "Perl 6?"
[14:41:56] havenwood: https://github.com/perl6/problem-solving/issues/81
[14:45:14] kyrylo: has joined #ruby
[14:47:29] deepredsky: has joined #ruby
[14:49:09] snapcase: has joined #ruby
[14:49:31] suukim: has joined #ruby
[14:49:35] leitz: havenwood, have you had too many energy drinks?
[14:51:21] havenwood: leitz: that reminds me... coffee time!
[14:52:07] code_zombie: has joined #ruby
[14:55:48] leitz: havenwood, when you get back, I'll go back to the "Lines 86-88" question. If there was an answer I missed it in the reboot. I did add your comments so I can track them.
[14:56:05] tsujp: has joined #ruby
[14:56:57] havenwood: leitz: I think I missed the question.
[14:57:44] havenwood: leitz: About this code? https://github.com/LeamHall/resume/blob/master/bin/parse_jobs.rb
[14:57:54] havenwood: leitz: What's the issue you're running into?
[14:58:51] leitz: Yup. Lines 66-68 seem klugy. They previous block triggers an object build on the *next* new section, which means the last section in the file doesn't get created.
[14:59:16] leitz: Now lines 84-86.
[14:59:22] leitz: I added notes. :)
[15:01:07] kyrylo: has joined #ruby
[15:01:51] jenrzzz: has joined #ruby
[15:04:26] havenwood: leitz: An alternative to using a block with #open is to just: File.foreach(filename) do |line|
[15:05:05] havenwood: leitz: I'd recommend `next if line.empty?` here: https://github.com/LeamHall/resume/blob/master/bin/parse_jobs.rb#L62
[15:05:19] rippa: has joined #ruby
[15:06:42] havenwood: leitz: Instead of `data.count > 0` you can say `data.any?`.
[15:07:21] leitz: havenwood, there's only one data file for this.
[15:07:47] havenwood: leitz: File.foreach('input/leamhall_jobs.txt') do |line|
[15:08:23] havenwood: leitz: I'd put this `data` inside the if statement, since there's no need to create a new Hash if it's empty.
[15:08:26] havenwood: leitz: https://github.com/LeamHall/resume/blob/master/bin/parse_jobs.rb#L67
[15:08:37] leitz: havenwood, ah, gotcha. The foreach is the line, not the file.
[15:09:40] leitz: havenwood, I should just clear the hash in line 67. It gets repopulated for each job.
[15:10:19] Huck777: has joined #ruby
[15:10:24] leitz: I'm still in the transition from "Apprentice Generic Programmer" to "Apprentice Ruby Programmer".
[15:10:33] havenwood: jobs << Job.new(data) if data.any?
[15:10:50] havenwood: jobs << Job.new(data) unless data.empty?
[15:11:52] cd: has joined #ruby
[15:11:54] havenwood: leitz: This makes me feel like you should be creating the Array literal directly with these values: https://github.com/LeamHall/resume/blob/master/bin/parse_jobs.rb#L72-L75
[15:12:07] havenwood: leitz: Can you switch to Symbol values?
[15:12:57] havenwood: leitz: data = {start_date: start_date, end_date: end_date, title: title, employer: employer}
[15:13:46] leitz: havenwood, symbols should work. The end state is either a JSON or text file that can get loaded, and then use whatever "format" the particular resume needs to be in. The lines starting at L88 are the basis of what a format would be.
[15:20:08] leitz: Symbols work. Implementing some other things.
[15:24:47] deepredsky: has joined #ruby
[15:34:33] ellcs: has joined #ruby
[15:35:50] SeepingN: has joined #ruby
[15:36:08] AJA4350: has joined #ruby
[15:37:23] salerace: has joined #ruby
[15:43:36] sytherax: has joined #ruby
[16:02:07] Ryctolagus: has joined #ruby
[16:10:34] matheusmoreira: has joined #ruby
[16:11:38] jenrzzz: has joined #ruby
[16:12:18] bruce_lee: has joined #ruby
[16:12:18] bruce_lee: has joined #ruby
[16:21:36] Frem: has joined #ruby
[16:24:34] kyrylo: has joined #ruby
[16:28:42] Swyper: has joined #ruby
[16:37:18] ukd1: has joined #ruby
[16:41:54] eddof13: has joined #ruby
[17:01:46] bruce_lee: has joined #ruby
[17:02:14] sytherax: has joined #ruby
[17:03:37] duderonomy: has joined #ruby
[17:06:40] jokke: hey there
[17:06:56] jokke: i'm trying to figure out how to write c bindings for ruby
[17:07:15] jokke: i'm struggling a bit with methods
[17:08:14] jokke: so from the docs i gathered that the function i pass to the rb_define_method function will be called with the ruby instance of the object the method was called on
[17:09:45] jokke: the question is, how can i get the initializer to store a pointer to the instance on c level.
[17:10:08] jokke: and how can i access that pointer from the function i pass to rb_define_method
[17:11:04] jokke: what i'm actually trying to do is write something in crystal and use it from ruby
[17:11:33] jokke: crystal too is object oriented so i'd need to call methods on an instance of the corresponding crystal class
[17:12:08] jokke: what i'm struggling with is how to associate the crystal instance with the ruby instance
[17:12:58] havenwood: jokke: You can create a gem with a Crystal extension then embed MRuby in your Crystal code.
[17:13:03] havenwood: jokke: https://gist.github.com/havenwood/afc514180e9aa18caaf2
[17:13:20] havenwood: For... reasons.
[17:13:32] Ryctolagus: has joined #ruby
[17:13:34] havenwood: jokke: Have you tried Fiddle and Fiddle::Importer?
[17:13:43] jokke: havenwood: ah no, i don't mean it that way
[17:13:53] jokke: i want to be able to use my crystal classes from ruby
[17:14:23] jokke: havenwood: no, haven't heard of fiddle
[17:14:52] jenrzzz: has joined #ruby
[17:15:20] havenwood: jokke: https://www.honeybadger.io/blog/use-any-c-library-from-ruby-via-fiddle-the-ruby-standard-librarys-best-kept-secret/
[17:15:45] havenwood: jokke: https://docs.ruby-lang.org/en/2.6.0/Fiddle.html
[17:16:25] havenwood: jokke: You can also do fun stuff within Ruby with Fiddle: https://gist.github.com/havenwood/0aa75f0c896a6dda0e56da5f21ed9fbd
[17:16:32] kyrylo: has joined #ruby
[17:16:56] havenwood: jokke: Gems like Typhoeus use FFI to interface with libcurl.
[17:17:07] jokke: yeah but FFI is meh
[17:18:49] havenwood: jokke: it seems a lot nicer to me than the C-ext interface
[17:19:19] havenwood: It's easy to use to wrap a C lib: https://blog.appsignal.com/2018/10/30/ruby-magic-building-a-ruby-c-extension-from-scratch.html
[17:20:11] havenwood: Fiddle is a bit nicer yet.
[17:22:29] havenwood: jokke: It'd be interesting if Crystal could generate dynamic libraries, but alas: https://github.com/crystal-lang/crystal/issues/921
[17:22:39] havenwood: https://github.com/ysbaddaden/crystal_library
[17:23:05] codefriar: has joined #ruby
[17:25:16] wildtrees: has joined #ruby
[17:26:51] wildtrees: has joined #ruby
[17:28:13] wildtrees: has joined #ruby
[17:36:35] _joes_: has joined #ruby
[17:40:30] ukd1: has joined #ruby
[18:03:03] ukd1: has joined #ruby
[18:03:51] Nicmavr: has joined #ruby
[18:03:55] ramfjord: has joined #ruby
[18:06:31] bmurt: has joined #ruby
[18:10:22] Xiti`: has joined #ruby
[18:26:37] fphilipe_: has joined #ruby
[18:37:29] gix: has joined #ruby
[18:38:46] s2013: has joined #ruby
[18:52:35] jenrzzz: has joined #ruby
[18:54:27] tdy: has joined #ruby
[18:57:46] tdy1: has joined #ruby
[18:59:27] eddof13: has joined #ruby
[19:00:39] teardown: has joined #ruby
[19:17:40] GodFather_: has joined #ruby
[19:17:46] GodFather: has joined #ruby
[19:32:45] SuperLag: has joined #ruby
[19:54:53] jidar: Can somebody tell me what exception catch I can write to catch only things found in net/smtp? I'm using the following code: https://gist.github.com/227c23a3cc478c65ce1af50a1f8eeb62 but it's catching errors further up the stack and causing the application to bomb abnormally
[19:56:02] jidar: it looks like there's a few Net::SMTP<something>Errors to catch?
[19:57:30] morenoh149: has joined #ruby
[20:04:19] jenrzzz: has joined #ruby
[20:05:38] havenwood: jidar: Net::SMTPError is mixed into all the other SMTP error classes, so you can just rescue it.
[20:06:51] havenwood: jidar: It's almost always a bad idea to: rescue Exception
[20:07:05] havenwood: jidar: A plain `rescue` is implicitly `rescue StandardError`.
[20:07:39] havenwood: jidar: rescue Net::SMTPError
[20:08:04] havenwood: jidar: You can omit `=> e` if you're not using `e`.
[20:08:49] fphilipe_: has joined #ruby
[20:12:55] jidar: groovy thanks havenwood
[20:20:21] AJA4350: has joined #ruby
[20:41:05] bmurt: has joined #ruby
[20:44:08] Retr0Punk: hey all, i am looking into adding templating to my program, that is, not HTML templating, but a template for the command line. for example, i'd like to have a config file where someone can input something like #{track} - #{title} - #{artist} and have the program output the correct data to the terminal. where could i start to look into doing this?
[20:45:33] darix: Retr0Punk: for that kind of stuff you dont even need a templating library
[20:46:23] unixcat_: has joined #ruby
[20:47:09] Norrin: sounds like homework
[20:47:26] Norrin: or an interview question
[20:47:38] Retr0Punk: it's not homework, i'm working on my project trying to learn ruby https://gitlab.com/DomenicF/track_list/tree/master
[20:48:01] havenwood: Retr0Punk: https://gist.github.com/havenwood/4469e3975ce0b597e00a3cf205dea4bb
[20:49:02] Retr0Punk: havenwood: that is HTML templating though, could i use ERB in the same fashion for templating on the command line?
[20:49:31] havenwood: Retr0Punk: I don't think "templating" is really what you want, after reading what you've said.
[20:49:37] havenwood: Retr0Punk: Folk often use a serialization format, like YAML, for config files.
[20:49:42] jenrzzz: has joined #ruby
[20:50:37] Retr0Punk: yeah i was thinking YAML, ok i will look into including that in my project, maybe read from a file or user input on the command line with YAML
[20:50:39] Retr0Punk: thank you :)
[20:54:36] eddof13: has joined #ruby
[20:54:37] leftylink: so. would it work if you just made them enter a string like '%<title>s' and then you just use % to format it?
[20:54:42] leftylink: &>> '%<title>s' % {title: :arghhh}
[20:54:48] rubydoc: stderr: playpen: timeout triggered! (https://carc.in/#/r/7dls)
[20:54:50] leftylink: then no library is needed, just the default capabilities of the language
[20:54:53] leftylink: &>> '%<title>s' % {title: :arghhh}
[20:54:54] rubydoc: # => "arghhh" (https://carc.in/#/r/7dlt)
[20:55:16] chalkmonster: has joined #ruby
[20:56:25] havenwood: Retr0Punk: https://gist.github.com/havenwood/d0533621d04269d7bd871c36f5c9f78a
[20:57:28] ellcs: has joined #ruby
[20:57:48] leftylink: if you're really set on not making them remember the exact format of %<title>s, maybe they think the angle brackets and the s are TOO BURDENSOME or something, then maybe you can just make them do <title> and you insert the % and s yourself
[21:01:57] Retr0Punk: leftylink: that is exactly what i need
[21:02:17] Retr0Punk: right now, i made a config file in my home directory including: output: "%TRACK%. %TITLE% (%LENGTH)"
[21:02:23] leftylink: also in case you ever came across a suggestion `eval ?" + template + ?"`, I highly recommend against :) since someone will set `template = '"; puts :pwned; "'`
[21:02:55] Retr0Punk: i then use YAML.load to load this into Ruby, but i am wondering if what you did with %<title> is some built in Ruby thing?
[21:03:07] SeepingN: has joined #ruby
[21:03:34] leftylink: please see the documentation for String#%
[21:03:39] leftylink: &ri String#%
[21:03:39] rubydoc: https://ruby-doc.org/core-2.6.3/String.html#method-i-25
[21:05:46] beanie__: has joined #ruby
[21:06:50] Retr0Punk: i don't see any angle brackets on this page :/ it's ok though, i can look into it more if it's really basic lol
[21:08:53] leftylink: although it is surely the case that the snippet of code `'%<title>s' % {title: :arghhh}` was indeed using String#%, there is no question about that. so the logical place to start looking at documentation is String#%
[21:09:18] leftylink: if it is so the case that the documentation for String#% asks one to look at other documentation, so too should that documentation be looked at.
[21:10:38] ur5us: has joined #ruby
[21:12:39] Retr0Punk: yes, i don't want to be a bother, i will look into it more. thank you
[21:21:28] leftylink: I can also add as a general point. sometimes it can be hard to tell whether a question would be a bother or not. it would be a shame if a person became too afraid to ask questions. but that is usually okay. people probably notice what I do. there are certain questions to which my answers take the form of "here are general rules that will help a person to know where to find the answer for oneself"
[21:21:54] galaxie: has joined #ruby
[21:22:21] leftylink: and it is that way because 1. (hopefully) it is helpful whether the asker was a vampire or not, and if they were a vampire I need to give that kind of answer for my own sake anyway. and 2. if I just tell them the answer they learn nothing
[21:23:12] leftylink: my general philosophy is nothing is magic though, so I hope to help allow people to see that it is not magic
[21:23:28] Retr0Punk: no i understand that, i am aware that what i am asking is pretty rudimentary stuff, and honestly i am not proud to need to ask these questions, as a professional developer, it just feels like Ruby is a completely new ecosystem to me and things aren't clicking in my brain as easy as i'd like them to. but i do not fault you for pointing me in the right direction, you have been very helpful
[21:26:32] poontangmessiah: has joined #ruby
[21:39:32] s2013: has joined #ruby
[21:45:22] tdy1: has joined #ruby
[21:47:13] queip: has joined #ruby
[22:06:41] ukd1: has joined #ruby
[22:11:19] mynameisdebian: has joined #ruby
[22:12:21] mynameisdebian: I have an Apache script serving a CGI script that responds to Slack events. Apache always takes several seconds to respond with "200 OK", and because of it Slack is throwing a message. How do I respond with 200 and send it right away with Ruby?
[22:14:54] bougyman: make it faster
[22:15:20] bougyman: This is a vague question, I can only give a vague answer.
[22:17:33] gix: has joined #ruby
[22:18:20] AJA4351: has joined #ruby
[22:19:14] poontangmessiah_: has joined #ruby
[22:23:54] baweaver: bougyman: be nice.
[22:24:09] baweaver: Instead, ask mynameisdebian for more details that help clarify the question
[22:24:47] baweaver: Such as what the script is, what code it has, if they've tested where the bottleneck is..
[22:27:37] morenoh149: has joined #ruby
[22:37:23] mynameisdebian: I have an Apache server running a Ruby CGI script. The CGI script receives a message from Slack, responds to Slack with "HTTP OK", then does a bunch of other stuff. It seems like the Apache server does not send 200 until the CGI script completes. Is there any way to make Apache return 200 without waiting for the script to complete?
[22:37:27] tpanarch1st_: has joined #ruby
[22:48:55] SeepingN: yes. Fork the meat of your app in a 2nd script.
[22:49:16] SeepingN: then return 200 and either wait for child to finish or just let it go unattached
[22:54:56] phenom: has joined #ruby
[22:56:05] mynameisdebian: SeepingN: Thank you for the reply. Is that a common solution, and this a common problem? Can you elaborate on "wait for child to finish or just let it go unattached"? What do you mean by those two options there?
[22:56:37] mynameisdebian: If I call the child script from the parent, won't the parent still take a long time to finish, and I'll still get the timeout error?
[22:56:58] SeepingN: not if you fire in the background. non-blocking.
[22:57:36] wildtrees: has joined #ruby
[22:57:46] SeepingN: system “#{RAILS_ROOT}/script/runner Project.my_method >/dev/null 2>&1
[22:57:47] rubydoc: parser error at position 0 around `”'
[22:58:59] havenwood: SeepingN: smart quotes?
[23:03:22] mynameisdebian: SleepingN, I just want to make sure because I am almost sleeping myself, is there any reason this solution would not work on Ruby without Rails?
[23:04:28] akem-hp_: has joined #ruby
[23:06:01] havenwood: mynameisdebian: Forking from the CGI process to do the background work should suffice.
[23:06:12] havenwood: mynameisdebian: It's certainly popular to use Rack for such things.
[23:06:36] havenwood: mynameisdebian: Rails is one of many Rack frameworks, but you don't need to use a framework with Rack at all.
[23:06:44] havenwood: mynameisdebian: https://rack.github.io/
[23:07:43] havenwood: mynameisdebian: if you wanted to be fancy, you could use Rack with a Redis-backed worker queue like Sidekiq.
[23:08:05] havenwood: Or just something Thread-backed, like Suckerpunch.
[23:08:35] havenwood: https://github.com/brandonhilkert/sucker_punch
[23:08:41] havenwood: https://github.com/resque/resque
[23:08:51] havenwood: https://github.com/mperham/sidekiq
[23:09:06] SeepingN: never knew what you wanted could get some complicated, eh
[23:09:29] havenwood: or just fork :P
[23:12:11] ukd1: has joined #ruby
[23:12:37] mynameisdebian: havenwood, I just need a way to send the 200 response and still run some code. Having a second script seems ok, but I'm trying to understand rack. Do you have a second to kind of explain those short examples on that page for me?
[23:14:19] havenwood: mynameisdebian: In CGI, by forking from your process or sending a task to a worker queue you can let the CGI script spin down so Apache sends the response.
[23:15:06] havenwood: mynameisdebian: Rack is an alternative, where you run a more sophisticated Ruby webserver that stays up between requests, unlike GCI which spins up a fresh Ruby process for each request.
[23:16:31] havenwood: mynameisdebian: By convention, you launch a Rack app from a config.ru file.
[23:16:48] havenwood: mynameisdebian: This line, for example, creates a simple Rack app in a single config.ru file:
[23:16:50] havenwood: echo "run -> _env { [200, {}, ['Hello World']] }" > config.ru
[23:17:03] havenwood: mynameisdebian: You can then run that ^ app with the command: rackup
[23:17:28] havenwood: mynameisdebian: Just install Rack, and usually you'll also want to install a Rack webserver like Puma too, rather than using the default.
[23:17:29] havenwood: mynameisdebian: gem install rack puma
[23:17:44] havenwood: mynameisdebian: Try creating that ^ config.ru, and running it with: rack
[23:17:55] havenwood: mynameisdebian: The `200` is the response code.
[23:18:11] havenwood: mynameisdebian: The empty Hash `{}` is for any Headers you want to set.
[23:18:21] havenwood: mynameisdebian: And the third argument is the body of the response.
[23:18:50] havenwood: mynameisdebian: You could spin up a thread, fork, use a worker queue, etc. to do some background work.
[23:19:30] havenwood: mynameisdebian: Does that make any sense? I'd suggest just playing with Rack a bit to get a feel for a simple Rack app.
[23:19:45] mynameisdebian: Does the Rack app contain the other code I want to run?
[23:20:24] havenwood: mynameisdebian: Yes, you can trigger that other code running from your Rack app. If you find you want to respond to more than one verb, routes, etc, consider using Roda on top of Rack: http://roda.jeremyevans.net/
[23:20:37] havenwood: mynameisdebian: It add a routing tree, for easy routing, and optional plugins.
[23:21:25] mynameisdebian: so, all I'm doing here is receiving a JSON message from Slack and responding with 200 OK, then taking information from that message and using it to place a call to another API. That API returns some data that is used to generate a Slack-formatted message, and then that message is posted back to a Slack endpoint
[23:22:24] havenwood: mynameisdebian: Here's an example of a Rack app that responds to all requests with 200 immediately, then five seconds laters logs "did work!":
[23:22:31] havenwood: echo "run -> _env { Thread.new { sleep 5; puts 'did work!' }; [200, {}, ['Hello World']] }" > config.ru
[23:22:40] havenwood: mynameisdebian: Run ^ that config.ru file with: rackup
[23:22:50] havenwood: mynameisdebian: Try it in the browser at: localhost:9292
[23:23:02] havenwood: mynameisdebian: You'll see an immediate response, then five seconds later a log entry.
[23:23:29] havenwood: mynameisdebian: Try doing the same with Roda.
[23:23:30] havenwood: mynameisdebian: gem install roda
[23:23:49] havenwood: mynameisdebian: It'll handle a ton more requests than CGI, fwiw.
[23:24:15] havenwood: mynameisdebian: If you see a config.ru file, you've spotted a Rack app.
[23:24:36] havenwood: mynameisdebian: Rails, Sinatra, Hanami, Roda, etc will all have a config.ru (Rack Up) file.
[23:24:56] havenwood: The default Rack webserver for Rails is Puma.
[23:25:18] mynameisdebian: havenwood, I'm confusing myself a little bit here. In this scenario is my Apache server still running on the server, serving the config.ru file?
[23:25:29] havenwood: I'd recommend Puma as a solid choice for whatever Rack app you're using.
[23:25:43] havenwood: mynameisdebian: You could serve Puma straight up on port 80, or 443, or you could reverse proxy from Apache to the port or socket that Puma is running on.
[23:25:54] havenwood: mynameisdebian: It's a very common setup to reverse proxy from Apache to Puma.
[23:26:13] havenwood: mynameisdebian: https://learnwithdaniel.com/2015/01/apache-puma-via-reverse-proxy/
[23:26:17] ukd1: has joined #ruby
[23:27:08] havenwood: mynameisdebian: I prefer the Nginx setup.
[23:27:28] havenwood: mynameisdebian: Falcon is a newer webserver than Puma that's meant to be run without Apache or Nginx.
[23:27:28] mynameisdebian: and in this case the Ruby webserver is always running, or does it have to be run on demand?
[23:27:38] havenwood: mynameisdebian: It would be always running.
[23:27:49] havenwood: mynameisdebian: Typically people just start Puma with systemd, which keeps it running.
[23:28:24] havenwood: mynameisdebian: http://www.mikeperham.com/2014/09/22/dont-daemonize-your-daemons/
[23:28:52] havenwood: mynameisdebian: Falcon has great performance served directly on port 443, fwiw: https://github.com/socketry/falcon
[23:29:00] havenwood: mynameisdebian: Puma is a more mainstream webserver.
[23:29:32] havenwood: mynameisdebian: You can swap a Rack app's webserver very easily between Puma, Passenger, Unicorn, Falcon, etc.
[23:29:38] mynameisdebian: It's a company webserver and I have to go through some admins to get anything done. I'm thinking it might be less complex in this case to have first script return 200 and make a system call to the other
[23:29:41] havenwood: mynameisdebian: There are a bunch of battle tested, high quality web server options.
[23:29:56] mynameisdebian: havenwood, I appreciate your time
[23:30:08] mynameisdebian: I'm going to re-read what you said and try to get a better grasp of it later on
[23:30:26] havenwood: mynameisdebian: please come back and inquire further if things come up
[23:30:29] havenwood: mynameisdebian: good luck!
[23:30:33] mynameisdebian: havenwood, thank you
[23:41:07] morenoh149: has joined #ruby
[23:47:43] cyclonis: has joined #ruby
[23:50:52] phenom: has joined #ruby