Activity Graph

Page 1 of 216 | Next »


[04:45:19] havenwood: marz_d`ghostman: Rails uses encrypted credentials these days. Lots of folk still use environment variables.
[04:47:17] havenwood: marz_d`ghostman: Here's simple encryption with the JOSE gem, fwiw: https://gist.github.com/havenwood/e18de5fa23ec1c49e3feab493d579909


[01:29:38] havenwood: GreenBio: please ask away!
[01:47:29] havenwood: GreenBio: Is Bundler installed on your current Ruby?
[01:47:37] havenwood: GreenBio: gem install bundler
[01:47:56] havenwood: GreenBio: If so, sanity check:
[01:47:57] havenwood: gem which bundler
[01:47:58] havenwood: which bundle
[01:47:59] havenwood: which -a bundle
[01:48:29] havenwood: which bundle | head -n1
[05:18:27] havenwood: So many Rubies this week. 2.5.5!
[05:19:18] havenwood: It includes some nice backported fixes.
[05:23:26] havenwood: In traditional font size names Pearl is 5 points, Ruby is 5.5 and Nonpareil is 6.
[05:24:10] havenwood: Or just skip to 28 points, Double English. I speak English, and program in Double English.
[15:09:05] havenwood: cek: HTTP.rb is quite nice. Typhoeus handles parallel requests well. Or there's always Net::HTTP in the stdlib!
[15:09:16] havenwood: cek: https://github.com/httprb/http#readme
[15:11:07] havenwood: cek: Here's a spreadsheet comparing various features between Ruby HTTP clients: https://docs.google.com/spreadsheets/d/1vPlk6nMIFa3sI5ISl7zZ5r6lDNpVQX6Jxi3ksXCyVbs/edit?usp=sharing
[17:23:04] havenwood: phaul: AI bandwidth engines set to full. engage!
[18:01:57] havenwood: phaul: I guess: ruby --jit -S rails db:seed
[18:21:31] havenwood: dionysus69: for some things, yes! for other things, no!


[14:58:05] havenwood: stimpy_: there's HABTM and the more flexible Has Many Through: https://rubyplus.com/articles/3451-Has-Many-Through-and-Has-and-Belongs-to-Many-in-Rails-5
[14:58:34] havenwood: stimpy_: https://medium.com/rubycademy/habtm-to-has-many-through-43f68f50e50e
[14:58:58] havenwood: stimpy_: https://guides.rubyonrails.org/association_basics.html#has-and-belongs-to-many-association-reference
[15:06:20] havenwood: stimpy_: ahh, i didn't catch that...
[15:06:56] havenwood: stimpy_: i don't know a recent writeup on same model habtm. if you haven't looked at it yet, there's: https://cobwwweb.com/bi-directional-has-and-belongs-to-many-on-a-single-model-in-rails
[15:07:04] havenwood: i can't vouch for the approach
[22:29:09] havenwood: &>> require 'ripper'; Ripper.sexp("'uptime'") == Ripper.sexp('"uptime"')
[22:30:18] havenwood: uplime: there's difference in how they're parsed, but they create the same Ruby AST - so they get evaluated identically by the VM.
[22:30:49] havenwood: uplime: the parsing speed difference should be negligible, if any
[22:31:08] havenwood: uplime: there's no IR evaluation speed difference


[17:11:52] havenwood: Yay for Ruby 2.6.2 and 2.5.4!
[17:12:40] havenwood: Some good bug squashing in 2.5.4: https://bugs.ruby-lang.org/issues/15617
[17:49:37] havenwood: They're both available in ruby-install and RVM now and there's a PR open for ruby-build.
[18:09:17] havenwood: Time to update Rails (CVE with dev RCE)! https://weblog.rubyonrails.org/2019/3/13/Rails-4-2-5-1-5-1-6-2-have-been-released/
[18:11:01] havenwood: Andr3as: What version of Rails?
[18:11:11] havenwood: Andr3as: Maybe this issue?: https://github.com/rails/webpacker/issues/1912


[23:35:54] havenwood: Bish: Mutexes aren't re-enntrant, but Monitors are (they use a ConditionVariable internally).
[23:37:16] havenwood: &>> Mutex.new.then { |lock| lock.synchronize { lock.synchronize { 42 } } }
[23:37:22] havenwood: &>> Monitor.new.then { |lock| lock.synchronize { lock.synchronize { 42 } } }


[15:40:26] havenwood: nakuku: Yes, you can define a #Router method that takes a block.
[15:40:45] havenwood: nakuku: (Similar to how #Integer, #String, etc work)
[15:41:18] havenwood: nakuku: https://gist.github.com/havenwood/b28b7fcac46518051b46acd3310ed5d4
[15:42:15] havenwood: phaul: ahh, yeah, that's not the most straightforward thing at all
[15:42:38] havenwood: phaul: nice, thanks for the fix! neat to have &ri work well
[15:42:55] havenwood: revirt: huh?
[15:50:39] havenwood: revirt: I think your markov chain poem is a better fit for #ruby-offtopic.
[15:50:49] havenwood: ?offtopic revirt
[15:53:40] havenwood: !kick revirt with a tip of the shades
[15:58:48] havenwood: jammanbo: no, that doesn't seem alarming for a Rails app
[15:59:09] havenwood: jammanbo: a random sample: :T_CLASS => 13945


[00:06:57] havenwood: bjpenn: how about heredoc with sprintf?
[00:08:29] havenwood: bjpenn: https://gist.github.com/havenwood/e867b667b35630ed9a9907225137bded
[00:08:43] havenwood: bjpenn: <<~'END' % {meaning: 42}
[00:23:38] havenwood: fun with ERB templates!
[00:23:57] havenwood: it's interesting that Ruby's JIT uses ERB :)
[00:25:06] havenwood: here's a simple ERB template i meant to do a writeup on to introduce folk to making their own templates: https://gist.github.com/havenwood/4469e3975ce0b597e00a3cf205dea4bb
[02:35:34] havenwood: mjacob: that reminds me of Elixir's Stream.repeatedly/1, which you can implement just like you showed: https://github.com/havenwood/elixir.rb/blob/master/lib/elixir/stream.rb#L29-L35
[02:36:35] havenwood: mjacob: https://gist.github.com/havenwood/40d3ae8acc87257624012b975816780e
[02:36:59] havenwood: mjacob: You could make a helper method like ^ and then: repeatedly { foo }.lazy
[22:00:54] havenwood: mkroman: it's in the stdlib under Digest
[22:01:13] havenwood: for anything
[22:04:51] havenwood: &ri Digest::SHA256.file
[22:05:14] havenwood: &ri Digest::SHA256::file
[22:05:34] havenwood: mkroman: anyhow, you can use Digest::SHA2 with IO


[01:51:12] havenwood: SeepingN: ActiveRecord?
[01:51:33] havenwood: SeepingN: Postgres?
[01:55:02] havenwood: SeepingN: How about?: Device.where('product LIKE %IQ6%').last
[01:55:56] havenwood: SeepingN: Device.where("product LIKE '%?%'", product_id).last
[01:56:14] havenwood: SeepingN: What is it?
[01:57:24] havenwood: SeepingN: How do you get a product, I don't follow. Have a code example showing how you call a product?
[01:58:13] havenwood: SeepingN: Okay, so you have a `part_num`. What on Device corresponds to that?
[01:59:22] havenwood: Let me back up. It seems you're trying to find a particular Device record given a part_num?
[01:59:37] havenwood: Showing a bit more code might give enough context.
[02:01:42] havenwood: SeepingN: My best guess, from what you've said, without seeing code is:
[02:01:43] havenwood: Device.find_each.find { |device| part_numbers.any? { |part_number| part_number.include? device.part_num } }
[02:02:38] havenwood: SeepingN: That would check Devices in batches of 1000, looking for a `device.part_num` that is a subset of one of the part_numbers Strings.
[02:04:36] havenwood: SeepingN: Device.find_each.find { |device| device.part_num.include? specific_substring }
[04:53:38] havenwood: has joined #RubyonRails-offtopic
[04:53:39] havenwood: has joined #RubyOnRails
[04:53:40] havenwood: has joined #ruby-offtopic
[04:53:44] havenwood: has joined #ruby
[20:07:54] havenwood: &>> require 'matrix'; puts 29.upto(32).map { |n| (Matrix[[0, 1], [1, 1]] ** n.pred)[1, 1] % n.pred + 140 }.tap { |a| a[-1] += 99 }.reverse.pack('C*').force_encoding('utf-8')
[20:23:21] havenwood: al2o3-cr: A domino isn't very far from a pizza!
[20:23:27] havenwood: &>> require 'matrix'; puts 29.upto(32).map { |n| (Matrix[[0, 1], [1, 1]] ** n.pred)[1, 1] % n.pred + 140 }.tap { |a| a[-1] += 99; a[1] -= 12 }.reverse.pack('C*').force_encoding('utf-8')


[02:31:34] havenwood: DaRock: I'm not familiar with any \r\n issue. Have a minimal reproduction case?
[02:36:01] havenwood: What version of Rack are you on?
[02:37:18] havenwood: DaRock: Assuming it's a Gemfile-based thing: bundle info rack
[02:38:18] havenwood: DaRock: gem list rack
[02:38:47] havenwood: or rather: gem list -e rack
[02:39:01] havenwood: or: rackup -v
[02:40:01] havenwood: DaRock: Yeah, like pip or npm.
[02:40:38] havenwood: DaRock: RubyGems/Bundler ship with Ruby and provide packaging and dependency resolution.
[02:40:49] havenwood: DaRock: Actually, a closer to Yarn.
[02:41:18] havenwood: DaRock: https://github.com/rack/rack/blob/7420be230f73ed350fb0aea612d0ea98cb451778/test/spec_lint.rb#L204-L216
[02:42:01] havenwood: I'm curious what the discrepancy is in the reading of 7230.
[02:48:00] havenwood: i'm missing the invalid part?
[02:50:10] havenwood: it looks to me like the spec is saying those are all valid characters
[02:52:01] havenwood: DaRock: right, but that's: "(),/:;<=>?@[\]{}
[02:54:33] havenwood: it's following 7230 as far as I can tell. maybe i'm just not getting it.
[02:56:00] havenwood: DaRock: \r is an invalid token, right?
[02:57:19] havenwood: DaRock: mind linking to the part of 8288 you mean?
[03:04:35] havenwood: DaRock: https://tools.ietf.org/html/rfc7230#section-3.2.4
[03:10:52] havenwood: Fun new addition to Rack, Eileen added trailer headers! https://github.com/rack/rack/commit/cf0b8eaf0e373e2a315f7be90ea7b2d3051aaa17
[03:15:31] havenwood: DaRock: "This specification deprecates such line folding"
[03:22:38] havenwood: DaRock: Maybe RFC 1796 explains it :P "Not All RFCs are Standards"
[03:24:25] havenwood: DaRock: maybe they're trying to avoid proposed standards relying on other proposed standards?
[03:25:26] havenwood: DaRock: yeah, it's chaos. here, Rack is targeting 7239 since Rack version 1.6.
[03:25:35] havenwood: It's 7230**
[03:26:14] havenwood: DaRock: now we need a standard for the nut/bolt adapter
[03:29:00] havenwood: application/text+plain; charset=utf-8; \r\nContent-Length:0\r\n\r\nHTTP/1.1 200 OK\r\n
[03:29:12] havenwood: DaRock: thanks for the interesting question - have good eats!
[05:03:53] havenwood: sagax: It's syntactic sugar for: Dir.[]("/")
[05:04:31] havenwood: sagax: Or you can omit the parens: Dir.[] "/"
[05:05:01] havenwood: sagax: More succinctly: Dir["/"]
[05:05:24] havenwood: sagax: You can define your own #[] or #[]=
[05:06:30] havenwood: &was >> module Sagax; def self.[] n; n.digits.join.to_i end end; Sagax[42]
[05:06:36] havenwood: &>> module Sagax; def self.[] n; n.digits.join.to_i end end; Sagax[42]
[05:53:51] havenwood: mjacob: /a#{/b/}/
[05:59:15] havenwood: mjacob: yeah, and a bit shorter than: Regexp.compile "#{/a|b/}#{/b/}"
[06:00:16] havenwood: mjacob: no, I don't know of a way to remove the options
[06:15:19] havenwood: this reminds me of the `o` option for interpolating only once: https://gist.github.com/havenwood/422e9fc9926328a3a192875aff519ddd
[08:30:19] havenwood: sagax: the latter is better: foo.respond_to?(:method)
[12:10:17] havenwood: kke: It automatically adds threads spawned by threads already in the group.
[12:10:51] havenwood: Or threads spawned by threads spawned by threads, and so on.
[12:10:53] havenwood: group = ThreadGroup.new; group.add Thread.new { Thread.new { Thread.new { sleep }; sleep }; sleep }; group.list.size #=> 3
[20:08:06] havenwood: kirun: zenspider: Nobu already fixed it :) https://github.com/ruby/ruby/commit/7fed9a2df50404c734504e0405ecaa98f0d9147c
[20:12:55] havenwood: sylario: i use this newfangled apache called "nginx" :P
[20:13:16] havenwood: for some reason the config drives me slightly less nuts
[20:13:41] havenwood: makr8100: You should be able to find good reverse proxy setups with Puma/Apache or Puma/Nginx.
[20:19:29] havenwood: makr8100: Or just serve Puma up on port 443.
[20:19:41] havenwood: makr8100: Falcon is a bleeding edge option.
[20:20:06] havenwood: https://github.com/socketry/falcon


[18:16:21] havenwood: ryouba: You *can* use upper case characters in an instance variable, but don't. There is a very strong convention for always using snake_case with instance variables.
[18:17:27] havenwood: ryouba: Conventions like this are partly because that's how Matz likes it aesthetically, but they serve an important role in facilitating ease of reading the code.
[18:20:46] havenwood: ytti: We've interestingly been enjoying Ruby for very large, long-term projects. I think part of the reason is that more time was spent in the Ruby codebases on testing and monitoring tools than in our Go and Java codebases.
[19:12:06] havenwood: robotcars: unless EVENT_DDL[event_table.to_sym].key?(k)
[19:12:39] havenwood: robotcars: change the `if` to an `unless` and remove the bang ("!")
[19:13:59] havenwood: robotcars: Switch `require` with `./` to `require_relative` with `./` removed: https://github.com/ccsd/ledbelly/blob/master/src/ledbelly_worker.rb#L1
[19:15:34] havenwood: robotcars: On line 22-3, you might consider #dig: ...attributes.dig('event_name', 'string_value')
[19:16:32] havenwood: robotcars: It's nice to `warn` with errors instead of `puts`, so it goes to stderr instead of stdout.
[19:16:49] havenwood: robotcars: #abort also takes an argument, which will print to stderr as well
[19:18:28] havenwood: robotcars: I prefer `$stdout.tty?`, just because I think it looks nicer.
[19:19:28] havenwood: robotcars: I'd suggest onelining: next if v.nil?
[19:19:38] havenwood: If the truthiness suffices: next unless v
[19:20:52] havenwood: robotcars: I'd extract this to a constant WARN_ERRORS and freeze it: https://github.com/ccsd/ledbelly/blob/master/src/ledbelly_worker.rb#L133-L141
[19:21:30] havenwood: same with `disconnect_errors`
[19:21:31] havenwood: robotcars: yup!
[19:22:01] havenwood: You can drop the `./` here: https://github.com/ccsd/ledbelly/blob/master/src/ledbelly_worker.rb#L168
[19:23:48] havenwood: robotcars: Actually, I'd probably go ahead and set the constant to: Regexp.union(disconnect_errors).freeze
[21:48:01] havenwood: c-c: rbenv maintains a dir of shims and puts that dir in your PATH
[21:49:10] havenwood: c-c: Switch to chruby for a quick fix. Or check your shim dir and figure out why it's either not in your PATH or the shims aren't being created
[21:49:31] havenwood: Net: yes, that was meant for you
[21:49:49] havenwood: Net: err, i'm not even close here - drinking more coffee
[21:52:29] havenwood: Net: How odd.
[21:54:41] havenwood: eightfold: it's expected that your installation directory will be in your gem paths.
[21:55:30] havenwood: eightfold: which in this case is true, but it's: /Library/Ruby/Gems/2.3.0
[21:55:36] havenwood: this looks like system Ruby
[21:55:44] havenwood: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
[21:57:45] havenwood: eightfold: so you're trying to use system Ruby to install gems locally?
[22:20:50] havenwood: eightfold: most folk recommend not using system Ruby with macOS, for various reasons: https://ryanbigg.com/2015/06/mac-os-x-ruby-ruby-install-chruby-and-you
[22:30:54] havenwood: kaleido: what's the error?
[22:34:58] havenwood: kaleido: that usually means you have an Array when you think you have a Hash
[22:36:32] havenwood: kaleido: What is?: parsed.class
[22:36:40] havenwood: kaleido: Array?
[22:37:05] havenwood: kaleido: then it's: parsed["weather"].class
[22:37:32] havenwood: kaleido: parsed["weather"].map { |weather| weather["main"] }
[23:11:26] havenwood: kirun: That seems like a CRuby-specific quirk that's reproducible with #method and #public_method.
[23:12:09] havenwood: kirun: Interestingly, CRuby, JRuby and TruffleRuby each have slightly different behavior here: https://gist.github.com/havenwood/679c6ad1dc018f0750389bd4c21abdc9
[23:12:53] havenwood: kirun: Note, with `foo.respond_to?('bar')` it'd be `:bar` across the board.


[17:52:14] havenwood: dontbecold_: share your Gemfile.lock?
[17:52:35] havenwood: dontbecold_: nothing unexpected?: bundle config
[18:48:58] havenwood: c-c: I've enjoyed the addition of `keyword_init:` to Structs too.
[18:49:43] havenwood: &>> Point = Struct.new(:x, :y, keyword_init: true); Point.new x: 42, y: -42
[20:09:51] havenwood: bjpenn: also mind showing us the output of?: bundle config
[20:13:08] havenwood: bjpenn: i'm more curious about the error and your bundle config.
[20:18:05] havenwood: bjpenn: aye, line 11 it shows you have --without set
[20:19:51] havenwood: bjpenn: look at the file: /Users/myuser/company/git.repo/.bundle/config
[20:20:21] havenwood: bjpenn: Bundler "remembered" to bundle without test and development and stored the setting there.
[20:20:42] havenwood: bjpenn: that's why you're not seeing Rubocop installed
[20:23:14] havenwood: bjpenn: yes, you likely ran `bundle install` command with --without=test,development, and didn't realize it would be "remembered"
[20:24:01] havenwood: bjpenn: you can manually remove the entry, or have bundler remove it for you with: bundle install --with=test,development
[20:25:31] havenwood: bjpenn: happy coding!


[19:10:07] havenwood: xc, oh they left?
[19:11:16] havenwood: I was going to suggest extracting an ALNUMS constant and #random_chars, #email_prefix and #duplicate methods.
[19:11:30] havenwood: And using #exists? over !#empty?
[19:11:58] havenwood: commented on the gist in any case


[00:13:21] havenwood: Darmani: You can drop the `self.`
[00:14:23] havenwood: Darmani: You have a valid arguement.
[00:17:58] havenwood: Darmani: You might consider renaming `string` to `grade` for symmetry and conveying meaning.
[00:18:19] havenwood: Darmani: you need to `include Comparable`
[00:18:42] havenwood: Darmani: I'd do 2, but pick your poison.
[00:18:52] havenwood: Darmani: No, it's up to you to mix it in.
[00:20:42] havenwood: though a- with a sword should clearly defeat a, so ¯\_(ツ)_/¯
[00:23:08] havenwood: Darmani: @grade is quicker yet than #grade, on line 13 - and it simplifies meaning for the reader
[00:23:43] havenwood: (I should have just said that immediately, multitasking)
[00:23:58] havenwood: I like using instance variables directly.
[00:24:23] havenwood: &ri Comparable
[00:25:01] havenwood: Darmani: They're light and quick and signify to the reader that you're getting and setting directly without having to read more.
[00:26:42] havenwood: Darmani: I usually put my includes/prepends/extends up top.
[00:36:00] havenwood: Darmani: Congrats! You can drop the `return`s
[00:38:44] havenwood: Darmani: Also a bit opposite on the +/0
[00:39:19] havenwood: + with +, - with -
[00:39:32] havenwood: you have + with -, - with +
[00:39:48] havenwood: Darmani: Grade.new("+") > Grade.new("-") #=> false # problem
[02:05:36] havenwood: mad_hatter: Are you familiar with Minitest?
[02:05:57] havenwood: bambanx: hi
[02:07:00] havenwood: welcome back!
[02:08:09] havenwood: mad_hatter: Minitest is the testing library that ships with Ruby.
[02:08:12] havenwood: mad_hatter: https://github.com/seattlerb/minitest#unit-tests
[02:08:39] havenwood: mad_hatter: Minitest and RSpec are the two most popular Ruby testing gems.
[02:14:54] havenwood: mad_hatter: https://gist.github.com/havenwood/8628f94348f15433336f021d309da39b


[02:35:20] havenwood: Swyper: Then you might consider: people.any? do |person|
[02:36:25] havenwood: Swyper: Then you can omit the if statement and the `return true` and `return false`.
[02:54:13] havenwood: Swyper: I think you mean #chars but you have #split.
[02:54:30] havenwood: &>> "aaoeee".split
[02:54:37] havenwood: &>> "aaoeee".chars
[02:55:00] havenwood: I agree with the suggestion to use a REPL!
[18:27:57] havenwood: amosbird: Are you familiar with Logger?
[18:29:31] havenwood: c-c: I'm curious - what's the advantage over communicating over say a UNIXSocket?
[18:30:31] havenwood: amosbird: That works!
[18:32:19] havenwood: c-c: mmmm, interesting...
[18:32:49] havenwood: c-c: I used to have a gem for IPC: https://github.com/havenwood/ifuture#usage
[18:33:22] havenwood: inter-process futures
[18:35:05] havenwood: amosbird: I just meant, no issue with just using tee. The simplest thing that can possibly work is a fine choice.
[18:36:31] havenwood: amosbird: Consider `warn` in place of `STDERR.puts`
[18:38:41] havenwood: c-c: yeah, it seemed like a nice approach to me too
[18:39:22] havenwood: c-c: I should maybe undeprecate ifuture now that Rob has revived ichannel.
[19:28:04] havenwood: barg: The reason to use pry-byebug is all of pry's features.
[19:28:25] havenwood: barg: The reason to use byebug alone is for the additional features that pry-byebug doesn't support.
[20:03:21] havenwood: amosbird: Dir["bench*{absl_H,robin_hood_h}ash"]
[23:43:45] havenwood: barg: For example, if you want to go right into exploring the stack without executing any code. You can just give the filename with `byebug` like `byebug hola.rb`. I'd image most folk use pry-byebug since Pry is popular.
[23:46:21] havenwood: &>> perfect = 'A+'; [perfect, perfect.next, perfect.chr.next, perfect.chr.next+?-, perfect.chr.next.next.next.next.next]
[23:47:09] havenwood: wait, this is ontopic!
[23:47:13] havenwood: &>> perfect = 'A+'; [perfect, perfect.next, perfect.chr.next, perfect.chr.next+?-, perfect.chr.next.next.next.next.next]
[23:50:49] havenwood: we should be able to post the answer into a queue and have it post in an hour
[23:50:57] havenwood: nice to show the real answer to the lurkers