havenwood

Activity Graph

Page 1 of 227 | Next »

2019-07-15

[15:55:55] havenwood: bretzel: they're two different gems for MySQL. use mysql2.
[16:20:54] havenwood: ngw: You could process nth lines in parallel. The parallel gem or parallel command should both work. You could do your own threaded version without too much fuss.
[16:21:47] havenwood: ngw: Or you could even try async-io, for a more modern, fiber-backed solution.
[16:22:24] havenwood: ngw: What you have is reasonably quick for a single-threaded solution with fairly low memory use.
[16:44:14] havenwood: &>> 'helloooooo'.squeeze 'o'
[16:45:03] havenwood: &>> alias g p; g'morning'
[17:16:11] havenwood: jamaio: Have an example of the logic you're talking about? Is the app already using service objects?
[17:18:11] havenwood: jamaio: I think _all logic_ is too broad of a generality, since controller logic to fetch or save from the model is appropriate for the controller.
[17:18:25] havenwood: jamaio: "A controller can thus be thought of as a middleman between models and views."
[17:19:31] havenwood: jamaio: It's fine if the logic in the controller isn't about getting the data it needs from a model to serve up in a view.
[17:19:38] havenwood: That's what controllers are for!
[17:22:10] havenwood: jamaio: Be suspicious of non-controller logic in the controller! If there's a recipe for french toast in your controller, or internal logic about using an API, or that type of thing, it probably doesn't belong there. If there's logic about which model info needs to be passed to the view, that's what controllers are for.
[17:25:00] havenwood: jamaio: Check out, for example, the types of things in controllers/ versus services/ here: https://github.com/discourse/discourse/tree/master/app
[17:25:52] havenwood: Also, TIMTOWTDI. I'd suggest sticking with Rails convention as close as you can until you have a good reason to go off the Rails.
[17:26:12] havenwood: jamaio: 👍🏽
[17:42:10] havenwood: Ah, ngw left, but commented on their gist showing a separate Fiber spun up to process each line: https://gist.github.com/ngw/54a544b7f9dcd8964d7d27ae84c754ac
[17:42:57] havenwood: Dunno why I even used an IO stream. I guess just multitasking fail. Anyways, seems several times faster on my machine. ¯\_(ツ)_/¯
[17:44:24] havenwood: jamaio: If the view doesn't end up with the right data from the model, the controllers aren't working. Rails has actually backed a bit away from tons of controller tests. There were some interesting articles on why.
[17:44:40] havenwood: jamaio: They're not particularly hard to unit test.
[17:47:53] havenwood: jamaio: I said that badly. I write functional tests for controllers. There were some helper functions for going deeper with controller tests that were removed, because they were seen as testing internals and not useful. You can use them as a gem now. https://guides.rubyonrails.org/testing.html#functional-tests-for-your-controllers
[17:48:28] havenwood: jamaio: I just meant #assigns, #assert_template, etc: https://github.com/rails/rails-controller-testing
[17:48:59] havenwood: jamaio: https://blog.bigbinary.com/2016/04/19/changes-to-test-controllers-in-rails-5.html#deprecation-of-assigns-and-assert_template-in-controller-tests
[17:50:11] havenwood: "The idea behind the removal of these methods is that instance variables and which template is rendered in a controller action are internals of a controller, and controller tests should not care about them."
[17:56:11] havenwood: leitz: I guess that's why I used an async stream
[17:56:54] havenwood: leitz: Seems a good bit faster on my machine for whatever reason. I barely had time to write it and do a single benchmark, so no attempts to tune
[17:57:07] havenwood: I may have got it wrong
[18:28:11] havenwood: Eiam: i'm skeptical of my own results too ;P just have to wait until this evening to get some free time to poke at it.
[18:29:17] havenwood: Eiam: ioquatix has a PR open that makes fiber allocation even faster with a fiber pool: https://bugs.ruby-lang.org/issues/15997
[18:29:44] havenwood: he's debating exposing the pool to users
[18:29:55] havenwood: or just under the hood
[18:30:11] havenwood: https://github.com/ruby/ruby/pull/2224
[18:31:00] havenwood: Eiam: ioquatix keeps implementing fibers in assembly :)
[18:35:22] havenwood: Eiam: i haven't looked at OS-specific tweaks
[18:36:34] havenwood: coroutines to improve performance of Fiber significantly. [Feature #14739]
[18:36:34] havenwood: Eiam: in 2.6: Native implementations (arm32, arm64, ppc64le, win32, win64, x86, amd64) of
[18:36:56] havenwood: https://bugs.ruby-lang.org/issues/14739
[19:47:35] havenwood: ytti: Here's an interesting thread with folk serving tens of millions of files per day experimenting with Falcon (libcoro under the hood since backed by fibers): https://github.com/socketry/falcon/issues/40
[23:36:25] havenwood: codefriar: Yes, some of us are very familiar with active record models.
[23:36:39] havenwood: oops, codie* left - sorry codefriar
[23:38:39] havenwood: vethis: Having a tty gem problem?

2019-07-13

[13:51:13] havenwood: danst: It sounds like one side is timing out after 10 seconds. You could probably just fix that issue, if you wanted to.
[13:51:27] havenwood: danst: A UNIXSocket seems reasonable. There are many options.
[13:53:16] havenwood: danst: https://github.com/shokai/ruby-socket.io-client-simple/blob/master/lib/socket.io-client-simple/client.rb#L82
[13:54:44] havenwood: danst: then it's divided by 1000 here: https://github.com/shokai/ruby-socket.io-client-simple/blob/master/lib/socket.io-client-simple/client.rb#L35
[13:55:20] havenwood: err, that'd still be a minute. ¯\_(ツ)_/¯
[13:57:44] havenwood: leitz: nice!
[20:29:47] havenwood: banister`: o/

2019-07-12

[15:10:14] havenwood: retromode: take(index + 1).each_with_index
[15:11:57] havenwood: retromode: or you can `break` once you reach the index you're looking for!

2019-07-11

[11:41:58] havenwood: Bish: Give one example of the desired result?
[11:51:56] havenwood: Bish: So you want #sample, as suggested. It doesn't take duplicates.
[11:52:19] havenwood: Bish: Yes, #sample.
[12:01:27] havenwood: Bish: You can implement #sample for a lazily sized Enumerator, but for an unsized one you have to iterate the entire collection just to count it anyways.
[12:01:51] havenwood: Bish: sized_enumerator.drop(rand(0...sized_enumerator.size)).first
[12:01:59] havenwood: &>> sized_enumerator = 1.upto(50); sized_enumerator.drop(rand(0...sized_enumerator.size)).first
[12:06:03] havenwood: Bish: That ^ one is lazily sized. The size is known.
[12:07:11] havenwood: &>> [].to_enum.size # This is not sized, for example.
[12:07:19] havenwood: &>> [].to_enum { 1 }.size # This is.
[12:07:51] havenwood: Bish: Note, the lazy size *can* be a lie. (It shouldn't be.)
[12:08:35] havenwood: I did a PR to change the output of #yield_self/#then to be a sized Enumerator, which meant teaching Ruby objects their size is one. :P
[12:09:00] havenwood: A tiny step towards object self awareness.
[12:09:57] havenwood: rb_obj_size(VALUE self, VALUE args, VALUE obj) { return LONG2FIX(1); }
[12:10:40] havenwood: &>> 42.then.size
[12:10:52] havenwood: So that's `1` now, not `nil`. :)
[12:11:13] havenwood: Dunno if it matters, but seems nice to me. ¯\_(ツ)_/¯
[12:12:05] havenwood: Actually, I'm pretty sure it doesn't matter. Still seems nice.
[16:32:02] havenwood: Inside: Python has really thorough coverage for graphics bindings.
[16:32:19] havenwood: A lot better than Ruby in that regard, unfortunately for Rubyists.
[16:55:54] havenwood: Jon30: Did you?: bundle install
[16:56:38] havenwood: Jon30: Is Devise in your Gemfile.lock?
[16:57:15] havenwood: Jon30: What's the command you run to get that error?
[16:58:09] havenwood: Jon30: I'm assuming cron isn't running in the context of your bundle. What's the command cron is running?
[16:59:17] havenwood: Jon30: What's the crontab executing? What command? It seems it's not in the context of your bundle, which you'd get by prefixing `bundle exec` or `bin/rake` from app root.
[17:00:08] havenwood: Jon30: Ah, yeah - that should be `bin/rake` or `bundle exec rake`. How'd you install Ruby?
[17:00:30] havenwood: Prefix `bundle exec` or it's not using your bundle!
[17:01:11] havenwood: https://i.imgur.com/2Hlpoov.png
[17:13:38] havenwood: Jon30: No, just running `rake` doesn't use your Bundle unless you're using RVM and are in the app directory.
[17:14:02] havenwood: Jon30: In modern Rails, you can use the `bin/rails` command for rake tasks.
[17:16:14] havenwood: Jon30: https://rvm.io/deployment/cron
[17:16:35] havenwood: Jon30: With RVM and cron, you might want to use wrappers. Wrappers are RVM's way of dealing with this scenario.
[17:17:11] havenwood: Jon30: RVM automagically prefixes `bundle exec` for you, but it doesn't work with cron.
[17:36:25] havenwood: ACTION stares into a glowing orb...
[17:57:57] havenwood: baweaver: Nice!
[19:17:33] havenwood: caduguedess: Looks like that project uses delayed_job for its worker queue. I'm assuming email is using that queue.
[19:17:47] havenwood: caduguedess: Are you running delayed_job locally?
[19:18:07] havenwood: caduguedess: RAILS_ENV=production script/delayed_job start
[19:18:19] havenwood: well, not the `production` bit :P
[19:20:08] havenwood: caduguedess: https://github.com/collectiveidea/delayed_job#running-jobs
[19:20:49] havenwood: caduguedess: Or better yet, these days: bin/rails jobs:work
[19:20:58] havenwood: caduguedess: then you're not running it
[19:21:06] havenwood: caduguedess: also run: bin/rails jobs:work
[19:21:14] havenwood: caduguedess: (From another terminal.)
[19:22:41] havenwood: It looks like neither script/delayed_job nor bin/delayed_job were generated, for whatever reason
[19:23:43] havenwood: caduguedess: Are you running Redis locally?
[19:24:10] havenwood: any log results from trying?: bin/rails jobs:work
[19:24:19] havenwood: yeah, Redis
[19:24:49] havenwood: caduguedess: Redis is what delayed_job uses to queue jobs.
[19:25:06] havenwood: caduguedess: What OS/distro are you on?
[19:26:46] havenwood: caduguedess: sudo apt-get update && sudo apt-get install -y redis-server && sudo systemctl start redis-server.service
[19:28:04] havenwood: caduguedess: Ah, looks like delayed_job supports multiple backends - not just Redis: https://github.com/collectiveidea/delayed_job/wiki/Backends
[19:29:06] havenwood: I usually use Sidekiq or Resque.
[19:29:29] havenwood: caduguedess: I don't see Redis listed as a dep, actually: https://github.com/openstreetmap/openstreetmap-website/blob/master/INSTALL.md
[19:30:29] havenwood: caduguedess: https://github.com/openstreetmap/openstreetmap-website/blob/master/app/mailers/notifier.rb
[19:31:31] havenwood: yeah, I've used SuckerPunch too.
[19:31:36] havenwood: adam12: I like the idea of fewer deps.
[19:32:15] havenwood: caduguedess: I may have led you on a wild goose chase as it seems they're not using jobs for mail...
[19:33:33] havenwood: caduguedess: It's been a while since I've used ActionMailer. If you haven't read the docs recently, they're probably worth a read: https://guides.rubyonrails.org/action_mailer_basics.html
[19:37:07] havenwood: caduguedess: Yes, I'd just uninstall it.
[19:37:08] havenwood: caduguedess: I was flat wrong.
[19:37:18] havenwood: caduguedess: I guessed first without looking at the repo. >.>
[19:39:12] havenwood: sudo systemctl stop redis-server.service && sudo apt-get purge -y redis-server &&
[19:39:41] havenwood: caduguedess: ^ that but no trailing &&
[19:40:33] havenwood: caduguedess: Or, maybe a bit better: sudo systemctl stop redis-server.service && sudo apt-get purge --auto-remove redis-server
[19:40:51] havenwood: caduguedess: (Stop the service, uninstall it.)
[21:07:14] havenwood: mlt-: Can you not wrap them both in a transaction?
[21:08:09] havenwood: mlt-: Have you already read?: https://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html
[21:08:42] havenwood: mlt-: "A transaction acts on a single database connection. If you have multiple class-specific databases, the transaction will not protect interaction among them. "
[23:53:38] havenwood: Neat extension for pattern matching: https://bugs.ruby-lang.org/issues/15865
[23:54:11] havenwood: This is something I've been wanting lately. Great to see an experimental go ahead!
[23:54:56] havenwood: even for very simple things, it's a great alternative to =/== ambiguity
[23:56:00] havenwood: `while message in connection.read` has none of the funkiness of `while (message = connection.read)`

2019-07-10

[05:50:23] havenwood: Quit: ZNC 1.7.3 - https://znc.in
[05:51:37] havenwood: has joined #ruby
[05:51:37] havenwood: has joined #RubyonRails-offtopic
[05:51:38] havenwood: has joined #RubyonRails-offtopic
[05:51:38] havenwood: has joined #ruby
[05:51:38] havenwood: Changing host
[05:51:53] havenwood: has joined #RubyOnRails
[05:51:54] havenwood: has joined #ruby-offtopic
[09:58:25] havenwood: Ping timeout: 248 seconds
[10:08:07] havenwood: has joined #ruby
[10:08:07] havenwood: has joined #RubyonRails-offtopic
[10:08:08] havenwood: has joined #RubyonRails-offtopic
[10:08:08] havenwood: has joined #ruby
[10:08:08] havenwood: Changing host
[10:08:19] havenwood: has joined #ruby-offtopic
[10:08:19] havenwood: has joined #RubyOnRails
[10:29:44] havenwood: Ping timeout: 268 seconds
[10:30:20] havenwood: has joined #RubyonRails-offtopic
[10:30:20] havenwood: has joined #ruby
[10:30:20] havenwood: Changing host
[10:30:20] havenwood: has joined #ruby
[10:30:20] havenwood: has joined #RubyonRails-offtopic
[10:30:46] havenwood: has joined #ruby-offtopic
[10:30:46] havenwood: has joined #RubyOnRails
[16:50:39] havenwood: Norrin: See this issue for some discussion of the design direction for keyword arguments in Ruby 3: https://bugs.ruby-lang.org/issues/14183
[16:51:31] havenwood: &>> RUBY_VERSION
[16:52:16] havenwood: NL3limin4t0r: In 2.6.3: def test(*options, a: nil); p options,a; end; a=22; test(1,2,3, a => "a string", a: 1)
[16:52:31] havenwood: #=> [[1, 2, 3, {22=>"a string"}], 1]
[17:01:09] havenwood: NL3limin4t0r: Yeah, this is a fairly rare case where a 2.6.0 feature had to be backed out due to unforeseen incompatibility.
[17:39:57] havenwood: Norrin: In 2.6.0, a prohibition was added to prevent passing both Symbol and non-Symbol keys at once.
[17:40:36] havenwood: Norrin: After 2.6.1 release, core team decided it needed to be backed out.
[17:41:28] havenwood: Norrin: NL3limin4t0r https://bugs.ruby-lang.org/projects/ruby-trunk/repository/trunk/revisions/67217/diff
[17:47:21] havenwood: bretzel: If you check, you'll see Node.js is written mostly in JavaScript. There's almost twice as much JavaScript as there is C++ with a little Python as well.
[17:47:36] havenwood: bretzel: v8 has more C++ than JavaScript.
[17:48:14] havenwood: bretzel: You probably just broke Ruby and didn't break Node.js. Messing around with multiple versions of Node would probably end you up somewhere similar.
[17:49:03] havenwood: bretzel: The reference implementation of Ruby is written in C.
[17:50:30] havenwood: bretzel: Are you a fan of C++? You seem to be citing it as an upside?
[17:54:05] havenwood: "C++ is a horrible language." -Linus
[17:54:31] havenwood: And that was the least flame-baity part of Linus' post. >.>
[17:58:30] havenwood: bretzel: "It's made more horrible by the fact that a lot of substandard programmers use it, to the point where it's much much easier to generate total and utter crap with it."
[17:59:00] havenwood: bretzel: "Quite frankly, even if the choice of C were to do *nothing* but keep the C++ programmers out, that in itself would be a huge reason to use C."
[18:03:13] havenwood: Aesthetics account for a surprising degree of folks' language selection too.
[18:04:30] havenwood: bretzel: "C++ leads to really really bad design choices."
[18:04:56] havenwood: bretzel: "In other words: the choice of C is the only sane choice."
[18:06:10] havenwood: bretzel: I don't know if Linus is motivated by hate, per se. He sure is opinionated. In any case, many folk really like Ruby. You may prefer Node.js. No reason to spread FUD about either.

2019-07-09

[00:02:36] havenwood: mlt-: You can refine whatever you want!
[00:03:02] havenwood: mlt-: Yeah, it was added in 2.6. (The SO solution you linked to presumes 2.6 it seems.)
[00:03:24] havenwood: mlt-: It was added in this issue: https://bugs.ruby-lang.org/issues/14035
[06:16:49] havenwood: vethis: just waiting for Ruby questions!
[06:22:05] havenwood: vethis: you're trying to echo in bash or a bash function or your Ruby script doesn't work from git-bash?
[06:22:35] havenwood: vethis: share the script?
[06:25:50] havenwood: vethis: So on git-bash you don't see "Gimme something: " until after you hit Enger?
[06:27:51] havenwood: vethis: Same result if you change `puts` to `STDOUT.puts` and change `gets` to `STDIN.gets`?
[06:31:28] havenwood: vethis: Try a STDOUT.flush after the first STOUT.puts?
[06:31:53] havenwood: vethis: Or: STDOUT.sync = true
[06:32:29] havenwood: vethis: Ah, so git-bash if buffering the output for some reason.
[06:33:00] havenwood: vethis: It should fix it if you up top once do a: STDOUT.sync = true
[06:34:25] havenwood: vethis: you're welcome
[06:34:32] havenwood: happy coding!
[06:34:59] havenwood: nope, I'm not familiar with Cmder.
[06:37:56] havenwood: vethis: Are you on Windows 10? You might try WSL or even WSL 2.
[06:38:03] havenwood: vethis: https://devblogs.microsoft.com/commandline/announcing-wsl-2/
[06:40:55] havenwood: vethis: do you even need the store for WSL? http://wsl-guide.org/en/latest/installation.html
[06:41:28] havenwood: Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
[06:41:42] havenwood: vethis: Run that ^ from PowerShell
[06:42:54] havenwood: I'm not sure what does or doesn't use the Store.
[06:46:02] havenwood: vethis: lxrun /install
[06:46:52] havenwood: vethis: or check? wslconfig /l
[06:47:38] havenwood: if the latter shows a distro, you can just use that
[06:48:59] havenwood: wsl --setdefault ...
[06:49:48] havenwood: vethis: good luck!
[06:50:03] havenwood: you're welcome
[16:36:51] havenwood: Scriptonaut: Can you tell from the exception whether it's open_timeout, read_timeout or ssl_timeout?
[16:38:22] havenwood: Scriptonaut: Does 1.8 work with modern ssl? I'm not spotting anything.
[16:38:34] havenwood: Scriptonaut: Does it work for non-ssl sites?
[16:42:53] havenwood: Scriptonaut: You might try setting a short `http.open_timeout = ..` then `http.read_timeout = ..`, etc.
[16:43:22] havenwood: I didn't use Net::HTTP until 1.9. :)
[16:44:38] havenwood: Scriptonaut: I was a lawyer back then. I did a different kind of code. :P
[16:47:07] havenwood: Scriptonaut: I suspect an ssl issue.
[19:05:04] havenwood: algun: That's not how status codes are supposed to work!
[19:05:41] havenwood: algun: The status code directly corresponds to the reason phrase, and is meant to be static.
[19:06:55] havenwood: algun: RFC-7230: "A client should ignore the reason-phrase content."
[19:52:11] havenwood: bjpenn: Normally you'd write: "-sX POST -w \"#{http_code}\""
[19:52:34] havenwood: bjpenn: You might consider not shelling out to curl, if that's an option.
[19:53:24] havenwood: bjpenn: There are solid gems with bindings to libcurl, Net::HTTP or other gems.
[20:03:05] havenwood: bjpenn: https://jhawthorn.github.io/curl-to-ruby/
[20:03:58] havenwood: https://github.com/jhawthorn/curl-to-ruby/blob/gh-pages/src/curlToRuby.js
[20:03:58] havenwood: bjpenn: Show the context of the code?

2019-07-08

[22:24:08] havenwood: mlt-: Another option: txt.partition(/(?:.*\n){,5}/).then { |_, before, after| before.lines << after }
[22:24:36] havenwood: mlt-: Yeah, or you could use #yield_self alias in 2.5.
[22:25:17] havenwood: mlt-: In 2.4 you could: _, before, after = txt.partition /(?:.*\n){,5}/; [*before.lines, after]
[22:25:58] havenwood: mlt-: That's ^ a little too ugly, so I'd probably do another solution.
[22:26:35] havenwood: mlt-: Also, there are edgecases around less than 5 total matches, which you could handle various ways depending on your requirements.
[22:27:49] havenwood: mlt-: There are simpler solutions, sec.
[22:28:16] havenwood: mlt-: lines = txt.lines; [*lines.first(5), lines.drop(5).join]
[23:31:40] havenwood: mlt-: Are you parsing user content to get file paths?
[23:32:34] havenwood: mlt-: I mean, are these user-supplied paths?
[23:32:52] havenwood: mlt-: You can ignore RuboCop when you feel like breaking the rubolaw.
[23:34:13] havenwood: mlt-: The reason RuboCop is objecting to Kernel#open is that you can invoke a command with it.
[23:34:39] havenwood: So ignore RuboCop :)
[23:35:22] havenwood: mlt-: The reason for the cop is to catch cases where you really mean to File.open, which is actually common.
[23:37:00] havenwood: mlt-: Something like: Security/Open: Excludes: -path/to/file.rb
[23:37:22] havenwood: but YAML and Exclude:
[23:37:57] havenwood: garyserj: {/} and do/end have different precedence.
[23:38:12] havenwood: garyserj: the rule is precedence.
[23:38:47] havenwood: &>> def abc x,y; end; abc 4,{"aa":"bb"} do end
[23:38:53] havenwood: garyserj: note that ^ works
[23:44:03] havenwood: mlt-: There's no harm I can think of in just opening the class to include a module.
[23:44:39] havenwood: mlt-: It's nicer to include a module to show where your patch came from.
[23:45:02] havenwood: mlt-: Alternatively, these days you can use refinements to lexically scope the patch - which is better yet.
[23:45:53] havenwood: mlt-: It's nicer to leave a module trail for the global monkey patching you're doing. It's nicer yet to not globally monkey patch and refine instead.
[23:47:08] havenwood: garyserj: yes
[23:49:05] havenwood: mlt-: For your case, you'd probably be prepending, not including, right?
[23:49:14] havenwood: mlt-: Refinements are something a bit different: https://docs.ruby-lang.org/en/2.4.0/syntax/refinements_rdoc.html
[23:49:41] havenwood: mlt-: Meant to link: https://docs.ruby-lang.org/en/2.6.0/syntax/refinements_rdoc.html
[23:51:41] havenwood: garyserj: a real keyword argument is not a Hash. Ruby used to not have keyword arguments, and only had naked Hashes for arguments. now Ruby has some keyword argument support, but there's still ambiguity. in Ruby 3 there's a proposal for *real* keyword arguments not equivocal with Hashes.
[23:52:48] havenwood: garyserj: Here's a tracking ticket with some background reading: https://bugs.ruby-lang.org/issues/14183
[23:54:58] havenwood: mlt-: That class variable (yuck) is at the URI module level, not at the URI::File class level.