Activity Graph

Page 1 of 34 | Next »


[22:52:00] Scriptonaut: has left #RubyOnRails: ()



[19:41:29] Scriptonaut: has joined #RubyOnRails
[19:43:45] Scriptonaut: hey all, I want to get some input from you guys. Every project I've ever worked on, we ran the staging server in a "staging" env, with RAILS_ENV='staging'. Someone I work with thinks that it will cause issues, and wants to run the staging server with RAILS_ENV='production'. What is the standard way to do it nowadays? Run staging in 'staging' or 'production'
[19:46:21] Scriptonaut: my reasoning is that we want different settings for staging, like the log level should be "debug", api's should point to sandboxes, it should read/write to staging buckets, etc. Running it in production would mean that it would run the risk of modifying customer data when we're testing things in staging. The alternative is that we use a single production.rb file for both staging and prod servers,
[19:46:28] Scriptonaut: and then use environment variables to load the various differences. I like the idea of just putting that stuff in staging.rb (or in the credentials.yml file if it's sensitive)


[17:29:07] Scriptonaut: has joined #RubyOnRails
[19:03:42] Scriptonaut: Hey all, I setup a staging server for my rails 5 app. It uses nginx + unicorn. The staging environment is currently identical to the production env file (I haven't actually made a production yet). When I hit the server, I get: ActionView::Template::Error (The asset "application.css" is not present in the assett pipeline). I want nginx to serve up my assets, not the asset pipeline.
[19:03:58] Scriptonaut: Here is my env file staging.rb: (Is there anything obviously wrong in there?)
[19:04:25] Scriptonaut: There is no $RAILS_SERVE_STATIC_FILES env var set by the way
[19:06:39] Scriptonaut: I ran: rails assets:precompile, and my public/assets dir is filled with application-#{some_hash}.css, application-#{some_hash}.js, and then a .gz version of both of those
[22:52:36] Scriptonaut: has left #RubyOnRails: ()


[00:14:18] Scriptonaut: I'm confused, what do you mean not invalid, like it's supposed to produce different keys between ruby processes?
[00:14:29] Scriptonaut: or between console sessions, etc
[00:14:58] Scriptonaut: that's the header
[00:15:02] Scriptonaut: it goes header.payload.signature
[00:15:32] Scriptonaut: header has the meta info about the type of encryption, etc, payload is the actual data, then signature is an encrypted concatenation of the header, payload, and secret
[00:15:37] Scriptonaut: used to verify the payload/header
[00:15:50] Scriptonaut: I suppose I should try decoding it
[00:15:53] Scriptonaut: and see if it for some reason works
[00:16:03] Scriptonaut: the second one is the same too?
[00:16:34] Scriptonaut: oh I see, that's odd, it's not always the case
[00:16:54] Scriptonaut: I'll try decoding and see what I get, thanks
[00:19:10] Scriptonaut: This will give me the perfect excuse to have this part of the codebase rewritten, I was saying we should decode rather than just comparing the encrypted strings
[00:21:17] Scriptonaut: zenspider: I don't know why I didn't think to do that
[00:22:05] Scriptonaut: hmm, never had that need. I use git for diffs most of the time
[00:22:41] Scriptonaut: you could try diffuse
[00:22:49] Scriptonaut:
[02:09:31] Scriptonaut: havenwood: you're right
[02:09:33] Scriptonaut: that's what it was
[02:09:52] Scriptonaut: I'm surprised you were able to deduce that
[02:10:45] Scriptonaut: the only part left that's bothering me, is that an existing dev built a system where he generated tokens like this, sent it to another service we have, and then used the token in a db query to lookup records.
[02:10:55] Scriptonaut: so somehow up until now, those hashes have always been in the same order
[02:11:02] Scriptonaut: but when I do it, I often get different ordered hashes
[02:11:44] Scriptonaut: no idea why when I do it, the key/value order changes regularly, but he managed to do it for months, on the same computer, and kept it in the same order
[02:11:59] Scriptonaut: I assume I will have to rewrite his lookup system that does lookups by the encrypted tokens, I don't see any other way around it
[02:12:14] Scriptonaut: not that it's a very good way of looking things up
[02:13:53] Scriptonaut: the payloads only hold a database record id
[02:14:03] Scriptonaut: but they're signed with a secret
[02:15:57] Scriptonaut: oh, we're just signing it with a raw string, is that not a good idea?
[02:16:14] Scriptonaut: like ENV["JWT_SECRET"]
[02:19:27] Scriptonaut: ah ok, thanks for the example. While working on this feature I noticed this stuff was used in several other places, and it definitely wasn't encrypting the payload. I'll have to check it out to make sure it's nothing that should be secure
[18:39:45] Scriptonaut: has left #ruby: ()


[19:47:30] Scriptonaut: has left #ruby: ()
[23:22:08] Scriptonaut: has joined #ruby
[23:24:03] Scriptonaut: I've had this issue for 2 days, JWT.encode keeps on giving me different tokens when I restart my console. Here's a gist demonstrating it perfectly
[23:24:17] Scriptonaut: giving me different tokens, with the same exact input**


[01:20:15] Scriptonaut: has left #RubyOnRails: ()
[01:20:17] Scriptonaut: has joined #ruby
[01:21:49] Scriptonaut: hey guys, I'm using JWT.encode and passing it a record id. It is generating the same key (as it should), however I've noticed when I restart my console, it will sometimes generate a different key. It only ever generates those two keys (with the same exactly input), one or the other, and I have to restart the console to get it to change (and it doesn't always)
[01:22:19] Scriptonaut: JWT.encode is supposed to generate the same thing every time, as long as the input is the same, but for some reason it's not


[21:27:38] Scriptonaut: has joined #RubyOnRails
[21:32:41] Scriptonaut: hey guys, I'm working on a rails 5 project, and it's filtering my sensitive params in the rails server log, authenticity_token, password, and token. The only part of my config that explicitly tells it to filter is an initializer called filter_parameter_logging.rb, with the line Rails.application.config.filter_parameters += [:password]. Why is it filtering the token ones as well? I don't want it to
[21:32:47] Scriptonaut: filter in development, how can I disable that filtering?


[21:20:42] Scriptonaut: has joined #ruby
[21:57:53] Scriptonaut: has left #ruby: ()


[00:02:15] Scriptonaut: has joined #ruby
[00:57:49] Scriptonaut: I'm having some really strane behavior with overriding a setter method on an object, I've explained the error in the gist I'm about to post, but I'll summarize here. I call super in a method override for a setter method. When I call that method, I get "NoMethoderror: super: no superclass method". However the original method is defined, when I comment out the method override definition I can call it just
[00:57:58] Scriptonaut:
[00:59:30] Scriptonaut: also when I comment out the method override, my_object.methods includes my method. So the error is complaining that there is no superclass method, when there definitely is a superclass method
[01:02:12] Scriptonaut: has joined #RubyOnRails
[01:03:25] Scriptonaut: I'm having some really strange behavior with overriding a setter method on an activerecord object, I've explained the error in the gist I'm about to post, but I'll summarize here. I call super in a method override for a setter method. When I call that method, I get "NoMethoderror: super: no superclass method". However the original method is defined, when I comment out the method override definitio
[01:03:31] Scriptonaut: n I can call it just fine
[01:03:34] Scriptonaut:
[01:03:50] Scriptonaut: also when I comment out the method override, my_object.methods includes my method. So the error is complaining that there is no superclass method, when there definitely is a superclass method
[01:07:08] Scriptonaut: superclass is PgsqlDatabase(abstract), and result of that grep is []. I'm not trying to call a method on the super class though, I'm trying to call the method that existed there before it was overrode
[01:08:18] Scriptonaut: hmm, this is so odd, isn't there a way to call the method that a certain method overrode?
[01:08:45] Scriptonaut: ya, you're right, I wonder what I was thinking. I confused something here
[01:09:10] Scriptonaut: I guess there probably isn't a way
[01:11:10] Scriptonaut: ya, me too, I could have sworn there was a common way to do this
[01:11:31] Scriptonaut: I think maybe I just got so used to using it in descended classes that I started to think I could use it everywhere
[01:12:14] Scriptonaut: ah ya that should work
[01:13:33] Scriptonaut: I think I figured out where I got confused. This is a text-based json column for an active record object. Normally I do this, but rather than super I call read_attribute(:blah)
[01:14:02] Scriptonaut: since this column already comes with a getter/setter out of the gate that parses the json text, I can't simply get rid of it and rely on read_attribute
[01:18:41] Scriptonaut: ya that will work for sure. I think it that level of confusion won't be worth it, I can just rename the original getter/setter, and then keep the current name for the setter override, and add a getter override as well
[01:18:54] Scriptonaut: I think that level**
[01:19:36] Scriptonaut: people won't think to look at the bottom of the file for X.prepend
[01:20:31] Scriptonaut: unless there's a way to do: def self.included(klass); klass.prepend my_method; end
[01:22:59] Scriptonaut: This guy ran into the same issue as me
[01:24:48] Scriptonaut: oh, that's pretty coo
[01:24:53] Scriptonaut: I think I'll do that
[01:25:38] Scriptonaut: ah I see, it's because the method is defined via metaprogramming
[01:25:51] Scriptonaut: in my example
[01:53:49] Scriptonaut: has left #ruby: ()
[01:53:56] Scriptonaut: has left #RubyOnRails: ()


[19:29:36] Scriptonaut: has left #ruby: ()


[21:13:00] Scriptonaut: has joined #ruby
[21:13:36] Scriptonaut: have you guys noticed how in the ruby console, if you override an assignment method, it will always return whatever you assign it to, even if the method returns false?
[21:14:04] Scriptonaut: I have a method that's like: def receive_notifications=(flag); User.current.is_admin? && super(flag); end
[21:14:53] Scriptonaut: in the console however, when User.current is a non-admin user, and I do: my_user.receive_notifications = true, the console prints "true" as the return value, even though I checked, and it's not true
[21:15:02] Scriptonaut: should I raise an error instead?
[22:15:49] Scriptonaut: LadyElusive: no I overrode the receive_notifications= method. THen I call super inside of it. The method returns false, I've tested it, but for some reason the console (only in the console, not when it runs anywhere else) short-circuits and displays the return value as whatever you pass to it. With a normal assignment method this is expected behavior, but I overrode the method and changed how it worked
[22:16:29] Scriptonaut: I'll gist the actual code
[22:19:25] Scriptonaut:
[22:19:30] Scriptonaut: that's odd behavior
[22:22:12] Scriptonaut: I made another gist that demonstrates the weird behavior:
[22:39:29] Scriptonaut: Eiam: exactly
[22:39:33] Scriptonaut: that's why I'm confused
[22:39:38] Scriptonaut: why is the console displaying true, when it's false
[22:40:12] Scriptonaut: no it's not, look at line 6
[22:40:16] Scriptonaut: it returns true
[22:40:47] Scriptonaut: when I do: ret_val = (gu.receive_direct_message_alerts = true), ret_val is assigned true
[22:41:14] Scriptonaut: only in the console though, when I run it on unicorn or even just through the interpreter it returns false
[22:42:15] Scriptonaut:
[22:44:54] Scriptonaut: Eiam: it's a cp_typed_hash on an ActiveRecord 2 model
[22:45:11] Scriptonaut: the method I wrote is to override the setter to prevent non-admins from having that setting set to true
[22:45:40] Scriptonaut: baweaver: it's not
[22:46:02] Scriptonaut: Eiam: I explicitly wrote the setter, the getter was defined by cp_typed_hash
[22:46:11] Scriptonaut: Eiam: yes, I wrote that
[22:46:18] Scriptonaut: and then call super, to the setter that was defined previously
[22:46:23] Scriptonaut: method overriding
[22:46:35] Scriptonaut: I only call super if the user is an admin though
[22:47:07] Scriptonaut: this is an issue with irb, the code is working as it should, it's just that in irb the return value is true when it should be false
[22:47:27] Scriptonaut: I wonder if it's a bug in old irb, this is ruby 1.8.7
[22:50:02] Scriptonaut: I gisted a console session, I am not confusing the getter and setter
[22:50:21] Scriptonaut: I just recreated it in irb with a test class:
[22:50:30] Scriptonaut: there, that's plain ruby, no activerecord, no method overriding
[22:50:36] Scriptonaut: it still has the issue
[22:50:58] Scriptonaut: as you can see, on line 6, the method x= should always return false
[22:51:06] Scriptonaut: however on line 15 it returns true
[22:51:42] Scriptonaut: when I do: t.x = "foo bar", it returns "foo bar"
[22:52:06] Scriptonaut: I'm gonna try in ruby 2.5 and see if the issue is still there
[22:54:05] Scriptonaut: hmm, still happens with ruby 2.5.1. It must just be the way the console is written. I always thought that the => in the console was supposed to denote the return value, but when the method ends with a '=', it returns the RValue no matter what
[22:54:53] Scriptonaut: this was my 2.5.1 run:
[22:55:05] Scriptonaut: oh well, it's not a big deal, the code works. I just thought that was weird
[22:57:33] Scriptonaut: well that would change the behavior because that's totally different code. The assignment in your example wouldn't be dependent on the first argument to &&
[22:57:42] Scriptonaut: that would assign @x to flag no matter what
[22:57:55] Scriptonaut: I came up with an even simpler example
[22:57:57] Scriptonaut: def foo=(bar); false; end
[22:58:08] Scriptonaut: f = true # This returns true
[22:58:13] Scriptonaut: foo = true **
[22:58:34] Scriptonaut: even though the method :foo= just returns false
[22:59:48] Scriptonaut: ya, pretty much. In my actual program I'm not doing condition && foo = bar, I'm just calling super(flag)
[23:02:00] Scriptonaut: this seems like it might be related
[23:03:19] Scriptonaut: someone wrote a blog post about it
[23:15:22] Scriptonaut: I just bundled fine, I wonder if it cached the locations of my gems since they're already downloaded though.
[23:18:29] Scriptonaut: there are various rubygem servers right?
[23:18:36] Scriptonaut: I wonder if the one you usually use is down
[23:18:56] Scriptonaut: same, I mean I think there are various physical servers, depending on your location
[23:19:47] Scriptonaut: ya, I've never had rubygems go down on me
[23:19:51] Scriptonaut: but it could be
[23:20:19] Scriptonaut:
[23:20:25] Scriptonaut: did you just ping that to get it?
[23:20:44] Scriptonaut:
[23:21:20] Scriptonaut: under ANSWER SECTION I got 4 rubygems.orgs, one of them is that one you are hitting
[23:21:34] Scriptonaut: they all have the same values other than IP
[23:21:57] Scriptonaut: I'm hitting the first one on the list, the 128 one you're hitting is the 3rd one
[23:22:29] Scriptonaut: it shows me that everything is operational, I'm hitting it fine
[23:22:35] Scriptonaut: Try hitting that:
[23:22:49] Scriptonaut: oh it doesn't like it when I try to hit it by ip
[23:23:48] Scriptonaut: microservices
[23:27:45] Scriptonaut: do you have a vps or something you could test it out on
[23:27:53] Scriptonaut: some remote server you could try pulling in rubygems from
[23:28:05] Scriptonaut: ah ok, must just be your connection
[23:41:31] Scriptonaut: cthulchu: you just mean to read? You could use awesome_print
[23:41:39] Scriptonaut: that will pretty print all kinds of things
[23:41:47] Scriptonaut: what's puts_r
[23:42:02] Scriptonaut: it's a tiny gem though iirc
[23:42:09] Scriptonaut: I always put awesome_print in my dev dependencies
[23:42:27] Scriptonaut: you could also download it and then just require it as needed I think


[03:18:55] Scriptonaut: has left #ruby: ()


[00:07:52] Scriptonaut: has left #ruby: ()
[20:32:02] Scriptonaut: has joined #ruby
[20:33:17] Scriptonaut: hey I was just wondering if any of you know an array method similar to .find, but rather than returning the first element that satisfies the condition, it returns a property/value of that element. So like if I had an array of object, I would want to return object.some_value of the first object that satisfies the condition, rather than returning the object itself
[20:33:49] Scriptonaut: I could easily do this in two lines, but I'm wondering if there's a shorthand oneliner way
[20:34:42] Scriptonaut: actually I might just change it to an each loop and then return the element explicitly, I just usually liek to avoid explicit return statements when it's at the tail-end of a method
[20:36:29] Scriptonaut: I only want the first element that satisfies the condition
[20:36:33] Scriptonaut: map would give me an array
[20:37:19] Scriptonaut: I could do `next if blah?` and then chain a `compact` to the end of the block but that would be janky
[20:38:49] Scriptonaut: that returns the element
[20:39:08] Scriptonaut: I need a method like find, but rather than returning the element, it returns a result I calculate in the block
[20:39:51] Scriptonaut:
[20:39:54] Scriptonaut: that's the method
[20:40:01] Scriptonaut: I need to return snomed_record.first
[20:50:33] Scriptonaut: woodruffw: find won't work
[20:50:48] Scriptonaut: find returns the element in the array, not a different value calculated from the element
[20:51:02] Scriptonaut: ya reduce was something I was thinking of
[20:51:51] Scriptonaut: I need the calculation in order to determine if it satisfies the condition, which is an expensive database lookup, I don't want to have to do that calculation twice. I think I'm just going to do an each loop and do an explicit return
[20:51:57] Scriptonaut: was just looking for a more 'ruby way' of doing it
[20:52:12] Scriptonaut: I'll checkout reduce
[20:52:20] Scriptonaut: haven't used that in a while
[20:53:34] Scriptonaut: selecting then mapping would incur a penalty because then the alg would become 2n rather than n (O)
[20:54:31] Scriptonaut: Eiam: because I'm looping over an array of object, then doing a db lookup for each one, then determining if the lookup yielded a sufficient result. If it did, then I need to return that result
[20:54:45] Scriptonaut: so I would have to calculate the result a second time once I returned teh element
[20:55:37] Scriptonaut: the lookup api can't take more than one param at a time
[20:55:49] Scriptonaut: so I can't do like Datasets::ICD10.snomedct_map([list, of, codes])
[20:55:59] Scriptonaut: I have to do it one by one
[20:56:19] Scriptonaut: lol, it's postgres, but the module was written that way
[21:15:17] Scriptonaut: ya, true, that's a decent solution, though I'd have to tack a .first on the end of it
[21:24:39] Scriptonaut: that wouldn't be a find_map would it?
[21:24:41] Scriptonaut: since each returns the whole list
[21:26:18] Scriptonaut: havenwood: that would return nil
[21:26:20] Scriptonaut: the thing you wrote
[21:26:31] Scriptonaut: oh n evermind
[21:26:36] Scriptonaut: I had no idea each worked that way
[21:26:47] Scriptonaut: I thought each always returned the original array
[21:26:52] Scriptonaut: unless the block specifies otherwise
[21:27:08] Scriptonaut: I didn't know you could pass an argument to break, that's awesome
[21:27:49] Scriptonaut: I use break all the time, but I didn't know if you passed it a value it would break from the block and return that value
[21:27:57] Scriptonaut: Does next also take a value?
[21:29:13] Scriptonaut: that's literally exactly how I solved my problem lol
[21:29:15] Scriptonaut: what your code is now
[21:29:52] Scriptonaut:
[21:30:18] Scriptonaut: havenwood: do you contribute to ruby?
[21:30:26] Scriptonaut: you were saying "we" when talking about removing features like that
[21:36:51] Scriptonaut: havenwood: nice. You mixed up the dx_code.code and dx_code.code_type in the else statement, but I like that idea better than mine (having an assignment operation inside a conditional)
[21:36:55] Scriptonaut: and ya, I shoulda used .any?


[20:25:01] Scriptonaut: has joined #ruby
[20:44:58] Scriptonaut: hey guys, I'm working on a really old project that uses activerecord 2, I'm having an issue with connections to the database persisting after I've ran the query, and returned from the method. Here is a basic rundown of what is happening:
[20:45:42] Scriptonaut: this ends up meaning that when I iterate a few hundred time, it ends up maxing out my max connection pool within a few seconds
[20:46:35] Scriptonaut: each time I call the method that runs this query, I return an array of the results (not an activerecord relation), yet the connection stays open
[20:49:00] Scriptonaut: oh, ya it is, but isn't Sequel an activerecord wrapper?
[20:49:24] Scriptonaut: ah, ok. I guess this is a sequel problem
[20:49:34] Scriptonaut: or is it behaving as intended?
[20:52:34] Scriptonaut: havenwood: thanks


[02:53:25] Scriptonaut: has left #ruby: ()


[00:51:45] Scriptonaut: &>> 'A..A..'.gsub(/(\w)(\.+)(\w)/) { $~[1] == $~[3] ? $~[0].gsub('.', $~[1]) : $~[0] }
[00:51:49] Scriptonaut: &>> 'Z..A..'.gsub(/(\w)(\.+)(\w)/) { $~[1] == $~[3] ? $~[0].gsub('.', $~[1]) : $~[0] }
[00:52:00] Scriptonaut: &>> 'Z..Z..A..A..'.gsub(/(\w)(\.+)(\w)/) { $~[1] == $~[3] ? $~[0].gsub('.', $~[1]) : $~[0] }
[00:52:07] Scriptonaut: thanks al2o3-cr
[00:52:32] Scriptonaut: the regexp stuff?
[00:52:44] Scriptonaut: no I just typed it in my console, but it is running in 1.8.7
[00:52:53] Scriptonaut: it was pretty gross to begin with
[00:52:58] Scriptonaut: I would probably just write a method for this
[00:53:24] Scriptonaut: yours isn't the actual solution
[00:53:26] Scriptonaut: it only works with A
[00:53:37] Scriptonaut: it has to work with any character